c++ - OpenCV:在一个窗口中录制素材并在第二个窗口中显示相同的视频,但仅包含轮廓

标签 c++ opencv

我想捕获视频并将其显示在一个窗口上,并在第二个窗口中同时显示轮廓。我正在为如何在第二个窗口中显示处理后的视频而苦苦挣扎。请分析我的代码并提出解决方案或指出哪里出了问题,也许会给我一些在线教程或资源的指导。谢谢。

     #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;
}

最佳答案

您应该在调用 drawContours 之后调用 imshow("Processed", result);

关于c++ - OpenCV:在一个窗口中录制素材并在第二个窗口中显示相同的视频,但仅包含轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14543088/

相关文章:

c++ - 打印内存地址

c++ - 没有匹配的函数调用 C++

c++ - ranges-v3 中的洗牌 Action

javascript - 如何将 OpenCV.js 集成到 React WebApp 中?

python - 如何在opencv python中放置驻留时间

c++ - 将队列转换为堆栈?

math - 哪种度量表明数据平滑变化?

c++ - 直接减去两个 vector<point2f>

c++ - 在 OpenCV 中访问 Mat 二值图像元素

c++ - C++中的多个降序对象