c++ - convert Qimage to cvMat 64FC3 format -
i have searched lot on internet have found how convert qimage rgb format, want convert qimage cv mat format cv_64fc3. have bad results when work cv_8uc3
here code :
qimage myimage; myimage.load("c://images//polarimage300915163358.bmp"); qlabel mylabel; mylabel.setpixmap(qpixmap::fromimage(myimage)); //mylabel.show(); cv::mat image1 = qimage2mat(myimage); mat img; image1.convertto(img, cv_64fc3, 1.0 / 255.0);
and here function used :
cv::mat qimage2mat(qimage const& src) { cv::mat tmp(src.height(),src.width(),cv_8uc3,(uchar*)src.bits(),src.bytesperline()); cv::mat result; // deep copy in case (my lack of knowledge open cv) cvtcolor(tmp, result,cv_bgr2rgb); return result; }
please me m new both opencv , qt
not sure mean bad results, assuming qimage loads image opencv (bgr
). in documentation tells use argb
.
so, knowing have 2 options:
- convert
qimage::format_rgb888
qimage
using functionconverttoformat
, linecvtcolor(tmp, result,cv_bgr2rgb);
not needed, since in rgb. - use
cv_8uc4
when creatingcv::mat
, drop first channel (channel alpha) using either split , join or mixchannels.
Comments
Post a Comment