Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV: record footage in one window and Display the same video in 2nd window but with contours only

Hey peeps i wont to capture a video and display it on one window and have second window in which contours are displayed simultaneous. Am struggling with how to have the processed video displayed in the second window. Please analyze my code and suggest a solution or indicate where am going wrong maybe give me some directions to an online tutorial or sources Thx.

#include "iostream"
    #include<opencv\cv.h>
    #include<opencv\highgui.h>
    #include<opencv\ml.h>
    #include<opencv\cxcore.h>
    #include <iostream> 
    #include <vector>
    #include <string> 
    #include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat)
    #include <opencv2/highgui/highgui.hpp> // Video write

    using namespace cv;
    using namespace std;


    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(1);
     if (!capCam.isOpened()){
        cout<<"ERROR: Failed to Initialize Camera"<<endl;
        return 1;
     }
     else{
        cout<<"Camera Initialized"<<endl;
     }

 //Create Window
char* ImputFootage = "Source";
namedWindow(ImputFootage, CV_WINDOW_AUTOSIZE);
imshow(ImputFootage, frame);

char* OutputFootage = "Processed";
namedWindow(OutputFootage, CV_WINDOW_AUTOSIZE);
imshow(OutputFootage, frame);



 while(1){
    capCam>> frame;
    imshow("Source", frame);
    return(1);

    if(capCam.read(ImputFootage)){

        //Convert Image to gray & blur it
cvtColor( image, 
    image_gray, 
    CV_BGR2GRAY );

blur( image_gray, 
    image_gray2,
    Size(3,3) );
//Threshold Gray&Blur Image
threshold(image_gray2, 
    threshold_output, 
    thresh, 
    max_thresh, 
    THRESH_BINARY);

//2D Container
vector<vector<Point>> 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


    }
 }
char CheckForEscKey = waitKey(10);
return 1;
}