Conversion from QVideoFrame to Opencv
-
wrote on 11 Nov 2017, 08:45 last edited by
Hi all
I am facing issue in converting qvideoframe to opencv format. The pixelFormat() for the videoframe is "Format_YUV420p".
The piece of code where I do the conversion is shared below
[CODE]cv::Mat result(frame.height(), frame.width(), CV_8UC3,(uchar*)frame.bits());
cv::Mat tmp;
cvtColor(result, tmp, cv::COLOR_YUV2GRAY_I420);
return tmp;[/CODE]
-
Hi,
That's a bit light on information.
What image are you expecting ?
What image are you getting ?
What version of Qt are you using ?
What version of OpenCV are you using ?
What platform are you running your code on ? -
wrote on 15 Nov 2017, 10:23 last edited by
HI
I am working on
Qt5.9 , Linux Kernel 4.15.
Opencv 3.2
Compiler: ARM EABI5Currently , I am able to convert QVideoFrame to QImage using the below function
[Code] size_t byteSize = sizeof(uchar) * 4 * vidFrame.width() * vidFrame.height();
void data = malloc(byteSize);
QImage image = new QImage((uchar*)data,vidFrame.width(), vidFrame.height(), QImage::Format_ARGB32_Premultiplied,
m_cleanImg ,data);
[/Code]The QImage needs to be converted to cv::Mat , so that my Qr Scanner can read the Image. The Qr Scanner is written using zbar and opencv and the code is shared below
[Code]
QVideoFrame cloneFrame(frame);
int width = cloneFrame.width(); int height = cloneFrame.height();
ImageScanner scanner;
scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
Mat grey;
Mat iFormat(img.width(), image.height(), CV_8UC4, (void*)image.bits(),image.bytesPerLine());
size_t byteSize = sizeof(uchar) * 4 * cloneFrame.width() * cloneFrame.height();
void data = malloc(byteSize);
Image image(width,height,"Y800",(uchar)data,width*height); //Zbar library
int n = scanner.scan(image);
for(Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol)
{
std::vector<Point> vp;
// do something useful with results
std::cout<<"decoded: "<<symbol->get_type_name()<<"symbol: "<<symbol->get_data()<<"\n";
int n = symbol->get_location_size();
for(int i=0;i<n;i++){
vp.push_back(Point(symbol->get_location_x(i),symbol->get_location_y(i)));
}
RotatedRect r = minAreaRect(vp);
Point2f pts[4];
r.points(pts);
for(int i=0;i<4;i++)
{
line(myFrame,pts[i],pts[(i+1)%4],Scalar(255,0,0),3);
}}
[/Code]
-
Before diving further in, may I suggest taking a look at this KDAB article using QZxing ? It might simplify your setup.
-
Before diving further in, may I suggest taking a look at this KDAB article using QZxing ? It might simplify your setup.
-
@SGaist
Thanks
I have started working on the QZXing library , and will update soon in the forum with any issueswrote on 24 Nov 2017, 12:18 last edited byI am able to integrate the QZXING library and the source code with my application. But the new issue that comes is the QVideoFrames are of YUYV type
and there is no frame conversion provided with QZXING library.
Can i get support as i need to convert the yuyv frames to image (png) format. -
wrote on 24 Nov 2017, 15:38 last edited by
@FVKamlesh maybe this post is applicable to you. See the response about using Qt private API (at the risk of lost compatibility in the future)
-
@FVKamlesh maybe this post is applicable to you. See the response about using Qt private API (at the risk of lost compatibility in the future)
wrote on 24 Nov 2017, 18:01 last edited by@Pablo-J.-Rogina
Thanks . I will update any progress that happens -
Just in case, the conversion from YUYV is not overly complicated, you can take a look at the OpenCV implementation and apply it to your image data.
-
wrote on 14 May 2018, 06:28 last edited by
Using the OpenCV library, I was able to convert YUYV format to JPG format. The QZXing filter is able to read the JPG format but performance is slow.
The camera takes around 20-30seconds to read the converted jpg format.