Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You were trying to show frames even before they were captured with camera. Compiler was not giving you error because Mat were declared ,but they were without value (null), Moreover you were trying to display Mat image, but what you capture from camera is Mat frame. Also, you lack exit (esc sequence, and your wait key was OUT of camera loop.</p> <p>Anyway, here is your code (rewritten), I hope this is what you wanted.</p> <pre><code>#include &lt;opencv2/core/core.hpp&gt; #include &lt;opencv2/highgui/highgui.hpp&gt; #include &lt;opencv2/imgproc/imgproc.hpp&gt; #include &lt;cstdio&gt; #include &lt;iostream&gt; #include &lt;stdlib.h&gt; #include &lt;stdio.h&gt; using namespace std; using namespace cv; Mat image; Mat image_gray; Mat image_gray2; Mat threshold_output; Mat frame; int thresh = 100, max_thresh = 255; int main(int argc, char** argv) { //Capture Video VideoCapture capCam(0); if (!capCam.isOpened()) { cout &lt;&lt; "ERROR: Failed to Initialize Camera" &lt;&lt; endl; return 1; } else { cout &lt;&lt; "Camera Initialized" &lt;&lt; endl; } //Create Window char* ImputFootage = "Source"; namedWindow(ImputFootage, CV_WINDOW_AUTOSIZE); char* OutputFootage = "Processed"; namedWindow(OutputFootage, CV_WINDOW_AUTOSIZE); while (1) { capCam &gt;&gt; frame; imshow(ImputFootage, frame); if (capCam.read(frame)) { //Convert Image to gray &amp; blur it cvtColor(frame, image_gray, CV_BGR2GRAY); blur(image_gray, image_gray2, Size(3, 3)); //Threshold Gray&amp;Blur Image threshold(image_gray2, threshold_output, thresh, max_thresh, THRESH_BINARY); //2D Container vector&lt;vector&lt;Point&gt; &gt; contours; //Fnd Countours Points, (Imput Image, Storage, Mode1, Mode2, Offset??) findContours(threshold_output, contours, // a vector of contours CV_RETR_EXTERNAL, // retrieve the external contours CV_CHAIN_APPROX_NONE, Point(0, 0)); // all pixels of each contours // Draw black contours on a white image Mat result(threshold_output.size(), CV_8U, Scalar(255)); drawContours(result, contours, -1, // draw all contours Scalar(0), // in black 2); // with a thickness of 2 imshow(OutputFootage, result); char CheckForEscKey = waitKey(10); //If the key pressed by user is Esc(ASCII is 27) then break out of the loop if (CheckForEscKey == 27) { break; } } } return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload