Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.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++ 线程在C++;_C++_Multithreading_Ip Camera - Fatal编程技术网

C++ 线程在C++;

C++ 线程在C++;,c++,multithreading,ip-camera,C++,Multithreading,Ip Camera,我希望有人能帮助我。我在Linux上的C++应用程序中工作,我使用线程和IPPrimor。 这是我的main.cpp代码: int main(){ cv::VideoCapture cap("rtsp://admin:admin@X.X.x.X/0/video1"); cv::VideoCapture cap2("rtsp://admin:admin@X.X.X.x/0/video1"); cv::VideoCapture cap3("rtsp://admin:admin@X.X.X.X/0/

我希望有人能帮助我。我在Linux上的C++应用程序中工作,我使用线程和IPPrimor。 这是我的main.cpp代码:

int main(){

cv::VideoCapture cap("rtsp://admin:admin@X.X.x.X/0/video1");
cv::VideoCapture cap2("rtsp://admin:admin@X.X.X.x/0/video1");
cv::VideoCapture cap3("rtsp://admin:admin@X.X.X.X/0/video1");
cv::VideoCapture cap4("rtsp://admin:admin@X.X.X.X/0/video1");

While(1)
{

   switch(value)
   {

case a:

  pthread_detach(t1);
  cvDestroyAllWindows();
  pthread_create(&t1, NULL, &video1, NULL);
  break;

case b:

  pthread_detach(t1);
  cvDestroyAllWindows();
  pthread_create(&t1, NULL, &video2, NULL);
  break;

case c:

  pthread_detach(t1);
  cvDestroyAllWindows();
  pthread_create(&t1, NULL, &video3, NULL);
  break;

case d:

  pthread_detach(t1);
  cvDestroyAllWindows();
  pthread_create(&t1, NULL, &video4, NULL);
  break;

   }
}
}
以下是video1、video2、video3和video4的代码:

extern int v1;

extern cv::VideoCapture cap ;


void* videoFrontConfiguration(void*) {


Display* disp = XOpenDisplay(NULL);
Screen*  scrn = DefaultScreenOfDisplay(disp);
int height = scrn->height;
int width  = scrn->width;

//Frame declaration
            cv::Mat frame;

            //Create window for the ip cam video
              cv::namedWindow("Front", CV_WINDOW_NORMAL);



              cvSetWindowProperty( "Front", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN );



               //Position of the screen where the video is shows
               cvMoveWindow("Front", 0, 0);
            cvResizeWindow( "Front", width, height );

            //while we keep connected to the ip camera, we process the frames we receive
            while ( cap.isOpened())
            {
                //we get the frame from the ip camera
                cap.read(frame);

                //if the frame is empty we break
                if(frame.empty()) break;

                //we show the video frame in "video" window
                cv::imshow("Front", frame);

                if(v1 == 1){
                    v1 = 0;


                    pthread_exit(NULL);
                }

                //To close the window
                if(cv::waitKey(20) >= 0) break;

            }

}
问题是,我正在使用RTSP摄像头,因此它是实时广播,但当我尝试运行应用程序并在几秒钟后开始显示摄像头时,会出现以下错误:

    [1;31m[h264 @ 0x1d430] out of range intra chroma pred mode at 20 9
    [0m[1;31m[h264 @ 0x1d430] error while decoding MB 20 9              
    [0m[1;31m[h264 @ 0x1d430] P sub_mb_type 5 out of range at 2 12
    [0m[1;31m[h264 @ 0x1d430] error while decoding MB 2 12
    [0m[1;31m[h264 @ 0x1f0b0] out of range intra chroma pred mode at 11 1
    [0m[1;31m[h264 @ 0x1f0b0] error while decoding MB 11 1        
所以我相信当我在主线程中进行捕获时,如下所示:

cv::VideoCapture cap("rtsp://admin:admin@X.X.x.X/0/video1");
然后我在另一个线程中渲染视频,可能是同步的问题。但老实说,我不确定,因为我没有太多的IpCameras经验

所以,如果有人有一些想法,使不动产同步或如果这是其他问题,请让我知道


非常感谢您

您正在创建cv::VideoCapture cap、cap1、cap2、cap3的四个实例,但在视频线程中您仅使用cap变量。所以,如果我没有弄错的话,四个线程将同时从同一个cv::VideoCapture实例读取数据。如果是这种情况,请尝试将cv::VideoCapture对象作为参数传递给pthread_create函数(即最后一个参数)