我没有显示我使用Opencv库获得的深度图。我尝试了cv :: imshow(“ Depth-Map”,disp8);在Try-Catch中它正在运行。但是我的Qt代码不起作用。我想将openCv imshow添加到自己的项目中或“ Qml是否具有深度图查看器?”
void VideoProvider::depthMap(Mat img1,Mat img2)
{
//two frames match between in there
QThread::currentThread()->msleep(60);
Mat im_left=img1;
Mat im_right=img2;
//for depth map start
cv::Size imagesize = im_left.size();
cv::Mat disparity_left=cv::Mat(imagesize.height,imagesize.width,CV_16S);
cv::Mat disparity_right=cv::Mat(imagesize.height,imagesize.width,CV_16S);
cv::Mat g1,g2,disp,disp8;
cv::cvtColor(im_left,g1,cv::COLOR_BGR2GRAY);
cv::cvtColor(im_right,g2,cv::COLOR_BGR2GRAY);
cv::Ptr<cv::StereoBM> sbm = cv::StereoBM::create(0,21);
sbm->setDisp12MaxDiff(1);
sbm->setSpeckleRange(8);
sbm->setSpeckleWindowSize(9);
sbm->setUniquenessRatio(0);
sbm->setTextureThreshold(507);
sbm->setMinDisparity(-39);
sbm->setPreFilterCap(61);
sbm->setPreFilterSize(5);
sbm->compute(g1,g2,disparity_left);
normalize(disparity_left, disp8, 0, 255, CV_MINMAX, CV_8U);
Mat mat(480, 640, CV_8UC4);
vector<int> compression_params;
compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
compression_params.push_back(9);
//depth map finish, return "Mat disp8"
try
{
//Problem is THIS!
readyfor2 = false;
cv::cvtColor(disp8, disp8, cv::COLOR_BGR2RGB); //Disp8(Depth-Map) is a Mat
outputImage2 = QImage((uchar*)disp8.data, disp8.cols, disp8.rows, disp8.step, QImage::Format_RGB888);
emit frameChanged2();
//Problem END
}
catch (runtime_error& ex)
{
fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
}
}
QML代码:dip8我用来显示qml代码。它是实时运行的
Image {
id: videoLayer2
x: 32
y: 22
width: 230
height: 186
clip: false
opacity: 1
anchors.right: parent.right
anchors.rightMargin: 371
anchors.bottom: parent.bottom
anchors.bottomMargin: 70
fillMode: Image.PreserveAspectFit
onSourceChanged:{
videoProvider2.framePainted2();
}
}
Connections
{
target: videoProvider2
property int frameCounter2: 0
onFrameChanged2:
{
videoLayer2.source = "image://videoCapture2/hoge" + frameCounter2;
frameCounter2 ^= 1;
}
}