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



  •     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


  • Lifetime Qt Champion

    Hi,

    Why would an OpenCV backend error be caused by Qt ?



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

    Regards
    Giorgio


  • Lifetime Qt Champion

    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.



  • @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


  • Lifetime Qt Champion

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



  • @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



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

    Rehards
    giorgio


  • Lifetime Qt Champion

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



  • 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


  • Lifetime Qt Champion

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



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.