VIDIOC_STREAMON: Bad file descriptor opencv 3.0
VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
VIDIOC_STREAMON: Bad file descriptor
Good news bad news .... I modified mi cap_v4l.cpp file in order to set EXPOSURE_ABSOLUTE camera parameter ... all ok ... Anyhow ... since I installed opencv3.0 I can not turn off and turn on the camera repeatedly without closing my app .... first with opencv 2.4.9 we could (though I used another system ..)... the simple code that I use ...
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.";
}
/************** NEW PIECE OF CODE OUT OF QT *** EXAMPLE CPP MODIFICATION FOR RE-OPEN CAMERA*********/
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/videoio.hpp"
#include <iostream>
using namespace cv;
using namespace std;
void drawText(Mat & image);
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;
//drawText(image);
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);
drawText(image1);
imshow("Sample", image);
//if(Key == 27) break;
}
if(cv::waitKey(1) == 27) break;
}
return 0;
}
void drawText(Mat & image1)
{
putText(image1, "Hello OpenCV",Point(20, 50),FONT_HERSHEY_COMPLEX, 1,Scalar(255, 255, 255),1, LINE_AA);
}
I'm on linux kernel 4.4.041 all is installed ok ... when I try run again my thread obtain 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*****/
/******************ERROR WITH C++ OPENCV CODE OUT OF QT***********************/
VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
Capture is opened
VIDIOC_STREAMON: Bad file descriptor
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/opencv-3.0.0/modules/imgproc/src/color.cpp, line 7349
terminate called after throwing an instance of 'cv::Exception'
what(): /home/opencv-3.0.0/modules/imgproc/src/color.cpp:7349: error: (-215) scn == 3 || scn == 4 in function cvtColor
Destroy
All type of suggest is well accept ...
Regards giorgio
I update the code with c++ opencv only code .... the same result .. not QT related problem.