gpt4 book ai didi

OpenCV GrabCut 算法示例不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 21:00:27 43 4
gpt4 key购买 nike

我正在尝试使用 C++ 在 OpenCV 中实现抓取算法我偶然发现 this site并找到了一种非常简单的方法。不幸的是,代码似乎对我不起作用

#include "opencv2/opencv.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main( )
{
// Open another image
Mat image;
image= cv::imread("images/mango11a.jpg");

// define bounding rectangle
cv::Rect rectangle(50,70,image.cols-150,image.rows-180);

cv::Mat result; // segmentation result (4 possible values)
cv::Mat bgModel,fgModel; // the models (internally used)

// GrabCut segmentation
cv::grabCut(image, // input image
result, // segmentation result
rectangle,// rectangle containing foreground
bgModel,fgModel, // models
1, // number of iterations
cv::GC_INIT_WITH_RECT); // use rectangle
cout << "oks pa dito" <<endl;
// Get the pixels marked as likely foreground
cv::compare(result,cv::GC_PR_FGD,result,cv::CMP_EQ);
// Generate output image
cv::Mat foreground(image.size(),CV_8UC3,cv::Scalar(255,255,255));
image.copyTo(foreground,result); // bg pixels not copied

// draw rectangle on original image
cv::rectangle(image, rectangle, cv::Scalar(255,255,255),1);
cv::namedWindow("Image");
cv::imshow("Image",image);

// display result
cv::namedWindow("Segmented Image");
cv::imshow("Segmented Image",foreground);


waitKey();
return 0;
}

谁能帮我解决这个问题?应该是什么问题PS:编译时没有打印错误。

最佳答案

再次检查您的设置。我刚刚执行了相同的教程,对我来说效果很好。 enter image description here

关于OpenCV GrabCut 算法示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15536222/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com