
6

gocv 这个库用法,求哥哥们指点
source link: https://www.v2ex.com/t/796896
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

找了个 C 代码是这样写的,问题是这个库在 cv::compare
的时候没有 这个 cv::GC_PR_FGD
我在库里面 cgo 调用时把它改为了 3
也是不行的。
有兄弟知道 gocv 怎么调用 grabCut 来抠图吗
cv::Mat image= cv::imread("../tower.jpg");
if (!image.data)
{
cout<<"不能打开图像!"<<endl;
return 0;
}
cv::Rect rectangle(50,70,image.cols-150,image.rows-180);
cv::Mat result;
cv::Mat bgModel,fgModel;
double tt = cv::getTickCount();
cv::grabCut(image,
result,
rectangle,
bgModel,fgModel,
cv::GC_INIT_WITH_RECT); // 用矩形
tt = cv::getTickCount() - tt;
printf("算法执行执行时间:%g ms\n", tt/cv::getTickFrequency()*1000);
cv::compare(result,cv::GC_PR_FGD,result,cv::CMP_EQ);
cv::Mat foreground(image.size(),CV_8UC3,cv::Scalar(255,255,255));
image.copyTo(foreground,result);
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK