Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenCV:在一个窗口中录制视频片段,并在第二个窗口中显示相同的视频,但仅显示轮廓_C++_Opencv - Fatal编程技术网

C++ OpenCV:在一个窗口中录制视频片段,并在第二个窗口中显示相同的视频,但仅显示轮廓

C++ OpenCV:在一个窗口中录制视频片段,并在第二个窗口中显示相同的视频,但仅显示轮廓,c++,opencv,C++,Opencv,我想捕获一个视频并在一个窗口上显示,然后在第二个窗口中同时显示轮廓。我正在努力使处理后的视频显示在第二个窗口中。请分析我的代码并提出解决方案,或者指出哪里出了问题,或者给我一些在线教程或资源的指导。谢谢 #include "iostream" #include<opencv\cv.h> #include<opencv\highgui.h> #include<opencv\ml.h> #include<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;
}
#包括“iostream”
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括//基本OpenCV结构(cv::Mat)
#包括//视频写入
使用名称空间cv;
使用名称空间std;
Mat图像;Mat图像的灰度;Mat图像_灰度2;Mat阈值输出;
垫架;
int thresh=100,max_thresh=255;
int main(int argc,字符**argv){
//捕获视频
视频捕获capCam(1);
如果(!capCam.isOpened()){

cout您应该调用
imshow(“Processed”,result);
调用
drawcours
后,您甚至在使用相机捕获帧之前就尝试显示帧。编译器没有给您错误,因为声明了Mat,但它们没有值(null),此外,您试图显示Mat图像,但从相机捕获的是Mat帧。此外,您缺少退出(esc序列),并且您的等待键不在相机循环中

无论如何,这是你的代码(重写),我希望这是你想要的

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>

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 << "ERROR: Failed to Initialize Camera" << endl;
        return 1;
    }
    else
    {
        cout << "Camera Initialized" << endl;
    }

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

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

    while (1)
    {
        capCam >> frame;
        imshow(ImputFootage, frame);

        if (capCam.read(frame))
        {

            //Convert Image to gray & blur it
            cvtColor(frame, 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

            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;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
使用名称空间cv;
Mat图像;
Mat图像的灰度;
Mat图像_灰度2;
Mat阈值输出;
垫架;
int thresh=100,max_thresh=255;
int main(int argc,字符**argv)
{
//捕获视频
视频捕获capCam(0);
如果(!capCam.isOpened())
{
库特