Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. opencv3.0 cam.release not work on qt5....
QtWS25 Last Chance

opencv3.0 cam.release not work on qt5....

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 2 Posters 4.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • gfxxG Offline
    gfxxG Offline
    gfxx
    wrote on last edited by
    #1
        if (!mo_cap.isOpened())
        {
            VideoCapture mo_cap; // open the default camer
            mo_cap.open(0);
        }
    
    
        if (mo_cap.isOpened())
        {
          do
          {
    
                QMutex mutex;
                mutex.lock();
                if(this->Stop) break;
                mutex.unlock();
    
                mo_cap.set(CV_CAP_PROP_GAIN, ex_gain);
                mo_cap.set(CV_CAP_PROP_EXPOSURE, ex_exposure_abs);
    
    
            controllokeypoint2 = 0;
    
    
            mo_cap >> dest_image1111;
            cvtColor(dest_image1111, dest_image, COLOR_BGR2RGB);
            dest_image1 = dest_image.clone();
    
            Mat2QImage(dest_image1); /**** these func send the video on Gui *******/
    
    this->msleep(30);
    }
    While(/*stop_capture button is checked*/)
    
    dest_image1111.release();
    dest_image1.release();
    dest_imag1111.release();
    mo_cap.release();
    
    qDebug() << "the camera thread is closed.";
    }
    
    
    

    If try to run more than one time my thread receive these error.....

    VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
    VIDIOC_STREAMON: Bad file descriptor
    VIDIOC_STREAMON: Bad file descriptor
    VIDIOC_STREAMON: Bad file descriptor  /**** one for every thread cicle*****/
    

    In opencv library with release capture the camera is off and no other definition or close command is required .... so i Think the problem is Qt5 related ...

    I use Qt5.6 ubuntu 14.04 (kernel 4.4.0.41, v4l2 and -dev is installed).

    Regards
    Giorgio

    bkt

    SGaistS 1 Reply Last reply
    0
    • gfxxG Offline
      gfxxG Offline
      gfxx
      wrote on last edited by gfxx
      #12

      I change cap_v4l.cpp file in these way and use CV_BGR2RGB for convert BGR image grabbed in normal RGC opencvstyle ....

      cap_v4l.cpp modifyed

      this is the new file ... after copy these into opencv3/module/videoio folder instead of original cap_v4l.cpp, You must re-build opencv3.0... after these in your "strange" camera it is possible to drive control EXPOSURE_ABSOLUTE using command CV_CAP_PROP_EXPOSURE ... (NOT CV_CAP_PROP_EXPOSURE_ABSOLUTE .... is not supported by opencv3)..

      Regards
      Giorgio

      bkt

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Why would an OpenCV backend error be caused by Qt ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • gfxxG Offline
          gfxxG Offline
          gfxx
          wrote on last edited by
          #3

          because if write the same code without QT (only c++ code) all work fine ....

          Regards
          Giorgio

          bkt

          1 Reply Last reply
          0
          • gfxxG gfxx
                if (!mo_cap.isOpened())
                {
                    VideoCapture mo_cap; // open the default camer
                    mo_cap.open(0);
                }
            
            
                if (mo_cap.isOpened())
                {
                  do
                  {
            
                        QMutex mutex;
                        mutex.lock();
                        if(this->Stop) break;
                        mutex.unlock();
            
                        mo_cap.set(CV_CAP_PROP_GAIN, ex_gain);
                        mo_cap.set(CV_CAP_PROP_EXPOSURE, ex_exposure_abs);
            
            
                    controllokeypoint2 = 0;
            
            
                    mo_cap >> dest_image1111;
                    cvtColor(dest_image1111, dest_image, COLOR_BGR2RGB);
                    dest_image1 = dest_image.clone();
            
                    Mat2QImage(dest_image1); /**** these func send the video on Gui *******/
            
            this->msleep(30);
            }
            While(/*stop_capture button is checked*/)
            
            dest_image1111.release();
            dest_image1.release();
            dest_imag1111.release();
            mo_cap.release();
            
            qDebug() << "the camera thread is closed.";
            }
            
            
            

            If try to run more than one time my thread receive these error.....

            VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
            VIDIOC_STREAMON: Bad file descriptor
            VIDIOC_STREAMON: Bad file descriptor
            VIDIOC_STREAMON: Bad file descriptor  /**** one for every thread cicle*****/
            

            In opencv library with release capture the camera is off and no other definition or close command is required .... so i Think the problem is Qt5 related ...

            I use Qt5.6 ubuntu 14.04 (kernel 4.4.0.41, v4l2 and -dev is installed).

            Regards
            Giorgio

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Are you sure you are using the same code as without Qt ?

            @gfxx said in opencv3.0 cam.release not work on qt5....:

            if (!mo_cap.isOpened())
            {
            VideoCapture mo_cap; // open the default camer
            mo_cap.open(0);
            }

            Here you are testing a variable called mo_cap, if not opened, you create a new one with the same name and open that one. This one will be destroyed right after the call to open.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            gfxxG 1 Reply Last reply
            0
            • SGaistS SGaist

              Are you sure you are using the same code as without Qt ?

              @gfxx said in opencv3.0 cam.release not work on qt5....:

              if (!mo_cap.isOpened())
              {
              VideoCapture mo_cap; // open the default camer
              mo_cap.open(0);
              }

              Here you are testing a variable called mo_cap, if not opened, you create a new one with the same name and open that one. This one will be destroyed right after the call to open.

              gfxxG Offline
              gfxxG Offline
              gfxx
              wrote on last edited by
              #5

              @SGaist said in opencv3.0 cam.release not work on qt5....:

              This one will be destroyed right after the call to open.

              You are in right ... it seems the problem is not QT related ... probabily v4l2 driver does not work the same way out of qt.

              Regards
              giorgio

              bkt

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #6

                What is the difference between your non-Qt and Qt implementation ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • gfxxG Offline
                  gfxxG Offline
                  gfxx
                  wrote on last edited by
                  #7

                  @SGaist .... two day ago I try a simple c++ code for try the difference ...

                  today I think is not right because my QT app work in qthread into while cycle.... so I write a new c++ app for simulate the QT app...

                  	#include "opencv2/core.hpp"
                  	#include "opencv2/imgproc.hpp"
                  	#include "opencv2/highgui.hpp"
                  	#include "opencv2/videoio.hpp"
                  	#include <iostream>
                  
                  	using namespace cv;
                  	using namespace std;
                  
                  
                  	char key = (char) cv::waitKey(30); 
                  	int test = 0;
                  
                  	int main()
                  	{
                  
                      
                  	    cout << "Built with OpenCV " << CV_VERSION << endl;
                  	    Mat image;
                  	    Mat image1;
                  	    VideoCapture mo_cap;
                  	    VideoCapture mo_cape;
                  	    mo_cap.open(0);
                       
                  
                  
                  	    mo_cap.set(CV_CAP_PROP_EXPOSURE, 450 );
                  	    mo_cap.set(CV_CAP_PROP_GAIN, 130 );
                  
                  
                  	for (;;)
                  	{
                  
                  	    if(cv::waitKey(1) == 32) 
                  	     {
                  		cout << "Built with OpenCV " << CV_VERSION << endl;
                  	        Mat image;
                  	        Mat image1;
                          
                   	       mo_cape.open(0);
                  	        mo_cape.set(CV_CAP_PROP_EXPOSURE, 450 );
                  	        mo_cape.set(CV_CAP_PROP_GAIN, 130 );
                  	         test = 1;
                   	    }
                  
                  	    if(mo_cap.isOpened() || mo_cape.isOpened())
                  	    {
                  	        cout << "Capture is opened" << endl;
                  	        for(;;) 
                   	       {
                  	            if(test == 0){mo_cap >> image;}
                  	            else {mo_cape >> image;}
                  	            cvtColor(image, image1, COLOR_BGR2RGB);
                  	            if(image1.empty())
                  	                break;
                  	            imshow("Sample", image1);
                  	            if(cv::waitKey(1) == 8) {mo_cap.release(); break;}
                  
                  	        }
                  
                                mo_cap.release();
                  	    }
                  	    else
                  	    {
                  	        cout << "No capture" << endl;
                  	        image = Mat::zeros(480, 640, CV_8UC1);
                  	        image1 = Mat::zeros(480, 640, CV_8UC1);
                  	        imshow("Sample", image1);
                  	    }
                  
                  	  if(cv::waitKey(1) == 27) break;
                  	}
                  
                  	    return 0;
                  	}
                  

                  In these way obtai the same output error in QT and c++ too...

                  VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV  /*********QT  1 time**********/
                  VIDIOC_STREAMON: Bad file descriptor
                  VIDIOC_STREAMON: Bad file descriptor
                  VIDIOC_STREAMON: Bad file descriptor
                  VIDIOC_STREAMON: Bad file descriptor/*************** QT 1 time every thread void run cycle *************************/
                  
                  VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV  /*********C++  1 time**********/
                  Capture is opened/*********debug string**********/
                  VIDIOC_STREAMON: Bad file descriptor/*********C++  1 time than program close .... there are not qthread with mutex **********/
                  
                  

                  The same result as you see....

                  I use cap_v4l.cpp file modified for gram BA81 format and drive EXPOSURE_ABSOLUTE & WHITE_BALANCE param (std file drive only EXPOSURE an no WHITE_BALANCE) .... these file can be 1 piece of problem ....
                  Other piece of problem maybe that I've compile opencv3.0 WITH V4L and GSTREAMER too ... I not known if the maybe a problem .... I can try to reinsytall opencv3.0 only with V4L option (the newest LIBV4L2 is not totally implemented in opencv, more option is not write in cap_libv4l2.cpp file and some grab matrix funcion as BA81 not appear in code).

                  Regards
                  Giorgio

                  bkt

                  gfxxG 1 Reply Last reply
                  0
                  • gfxxG gfxx

                    @SGaist .... two day ago I try a simple c++ code for try the difference ...

                    today I think is not right because my QT app work in qthread into while cycle.... so I write a new c++ app for simulate the QT app...

                    	#include "opencv2/core.hpp"
                    	#include "opencv2/imgproc.hpp"
                    	#include "opencv2/highgui.hpp"
                    	#include "opencv2/videoio.hpp"
                    	#include <iostream>
                    
                    	using namespace cv;
                    	using namespace std;
                    
                    
                    	char key = (char) cv::waitKey(30); 
                    	int test = 0;
                    
                    	int main()
                    	{
                    
                        
                    	    cout << "Built with OpenCV " << CV_VERSION << endl;
                    	    Mat image;
                    	    Mat image1;
                    	    VideoCapture mo_cap;
                    	    VideoCapture mo_cape;
                    	    mo_cap.open(0);
                         
                    
                    
                    	    mo_cap.set(CV_CAP_PROP_EXPOSURE, 450 );
                    	    mo_cap.set(CV_CAP_PROP_GAIN, 130 );
                    
                    
                    	for (;;)
                    	{
                    
                    	    if(cv::waitKey(1) == 32) 
                    	     {
                    		cout << "Built with OpenCV " << CV_VERSION << endl;
                    	        Mat image;
                    	        Mat image1;
                            
                     	       mo_cape.open(0);
                    	        mo_cape.set(CV_CAP_PROP_EXPOSURE, 450 );
                    	        mo_cape.set(CV_CAP_PROP_GAIN, 130 );
                    	         test = 1;
                     	    }
                    
                    	    if(mo_cap.isOpened() || mo_cape.isOpened())
                    	    {
                    	        cout << "Capture is opened" << endl;
                    	        for(;;) 
                     	       {
                    	            if(test == 0){mo_cap >> image;}
                    	            else {mo_cape >> image;}
                    	            cvtColor(image, image1, COLOR_BGR2RGB);
                    	            if(image1.empty())
                    	                break;
                    	            imshow("Sample", image1);
                    	            if(cv::waitKey(1) == 8) {mo_cap.release(); break;}
                    
                    	        }
                    
                                  mo_cap.release();
                    	    }
                    	    else
                    	    {
                    	        cout << "No capture" << endl;
                    	        image = Mat::zeros(480, 640, CV_8UC1);
                    	        image1 = Mat::zeros(480, 640, CV_8UC1);
                    	        imshow("Sample", image1);
                    	    }
                    
                    	  if(cv::waitKey(1) == 27) break;
                    	}
                    
                    	    return 0;
                    	}
                    

                    In these way obtai the same output error in QT and c++ too...

                    VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV  /*********QT  1 time**********/
                    VIDIOC_STREAMON: Bad file descriptor
                    VIDIOC_STREAMON: Bad file descriptor
                    VIDIOC_STREAMON: Bad file descriptor
                    VIDIOC_STREAMON: Bad file descriptor/*************** QT 1 time every thread void run cycle *************************/
                    
                    VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV  /*********C++  1 time**********/
                    Capture is opened/*********debug string**********/
                    VIDIOC_STREAMON: Bad file descriptor/*********C++  1 time than program close .... there are not qthread with mutex **********/
                    
                    

                    The same result as you see....

                    I use cap_v4l.cpp file modified for gram BA81 format and drive EXPOSURE_ABSOLUTE & WHITE_BALANCE param (std file drive only EXPOSURE an no WHITE_BALANCE) .... these file can be 1 piece of problem ....
                    Other piece of problem maybe that I've compile opencv3.0 WITH V4L and GSTREAMER too ... I not known if the maybe a problem .... I can try to reinsytall opencv3.0 only with V4L option (the newest LIBV4L2 is not totally implemented in opencv, more option is not write in cap_libv4l2.cpp file and some grab matrix funcion as BA81 not appear in code).

                    Regards
                    Giorgio

                    gfxxG Offline
                    gfxxG Offline
                    gfxx
                    wrote on last edited by
                    #8

                    without GStramer suppor is the same into qt & into C++ code...

                    Rehards
                    giorgio

                    bkt

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #9

                      From what you wrote, it looks like your modifications of the v4l backend is the problem.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • gfxxG Offline
                        gfxxG Offline
                        gfxx
                        wrote on last edited by
                        #10

                        the world everything can be , I' m not a good programmer (I'm not even a programmer) .... but unfortunately, before my changes I had problems, obviously with some errors in more than now ...in any case are not the only one with this kind of problem with opencv and linux ... unfortunately, each camera has its own system to compress files, and it is said that always goes well with all .... for example with a Logitec camera with RGB output I have no problem .... with and without changes, with V4l_cal or with libv4l_cap .....

                        any case, other guy find the best solution is not release the cam and symply use or not it put VideoCapture mo_cap; declaration in the header file and in void run using only mo_cap.open(n) .. with some msec of delay after use it ....

                        but if you are serious and want to look at the code please do me a voice that I am attaching the file ...

                        regards
                        giorgio

                        bkt

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #11

                          Did you try to just open that camera with one of OpenCV's examples ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • gfxxG Offline
                            gfxxG Offline
                            gfxx
                            wrote on last edited by gfxx
                            #12

                            I change cap_v4l.cpp file in these way and use CV_BGR2RGB for convert BGR image grabbed in normal RGC opencvstyle ....

                            cap_v4l.cpp modifyed

                            this is the new file ... after copy these into opencv3/module/videoio folder instead of original cap_v4l.cpp, You must re-build opencv3.0... after these in your "strange" camera it is possible to drive control EXPOSURE_ABSOLUTE using command CV_CAP_PROP_EXPOSURE ... (NOT CV_CAP_PROP_EXPOSURE_ABSOLUTE .... is not supported by opencv3)..

                            Regards
                            Giorgio

                            bkt

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved