資源簡介
使用opencv函數grabcut,實現前景和背景分離

代碼片段和文件信息
#include?“opencv2/highgui/highgui.hpp“???????????????????????????????????????????????????????????????????????????????????????????????
#include?“opencv2/imgproc/imgproc.hpp“
#include?
using?namespace?std;
using?namespace?cv;?
string?filename;
Mat?image;
string?winName?=?“show“;
Rect?rect;
Mat?mask;
const?Scalar?GREEN?=?Scalar(02550);
Mat?bgdModel?fgdModel;
void?setRectInMask(){
rect.x?=?110;
rect.y?=?220;
rect.width?=?100;
rect.height?=?100;
}
static?void?getBinMask(?const?Mat&?comMask?Mat&?binMask?){
binMask.create(?comMask.size()?CV_8UC1?);
binMask?=?comMask?&?1;
}
int?main(int?argc?char*?argv[]){
Mat?binMask?res;
filename?=?argv[1];
image?=?imread(?filename?1?);
mask.create(image.size()?CV_8UC1);
mask.setTo(GC_BGD);
setRectInMask();
(mask(rect)).setTo(Scalar(GC_PR_FGD));
rectangle(image?Point(rect.x?rect.y)?Point(rect.x?+?rect.width?rect.y?+?rect.height?)?GREEN?2);
imshow(winName?image);
image?=?imread(?filename?1?);
grabCut(image?mask?rect?bgdModel?fgdModel?1?GC_INIT_WITH_RECT);
getBinMask(mask?binMask);
image.copyTo(res?binMask);
imshow(“result“?res);
waitKey(0);
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????..A..H.?????12288??2015-05-13?20:48??背景分離\1_test\.test.cpp.swp
?????文件?????100919??2015-03-14?15:51??背景分離\1_test\1.jpg
?????文件??????21076??2015-05-13?20:47??背景分離\1_test\11
?????文件??????42832??2015-03-14?15:51??背景分離\1_test\2.jpg
?????文件??????53310??2015-03-14?15:51??背景分離\1_test\3.jpg
?????文件?????182461??2015-03-14?15:51??背景分離\1_test\4.jpg
?????文件?????123724??2015-03-14?15:51??背景分離\1_test\sky.jpg
?????文件???????1162??2015-05-13?20:47??背景分離\1_test\test.cpp
?????文件??????83359??2015-03-14?15:51??背景分離\1_test\w.jpg
?????文件??????25681??2015-05-13?20:43??背景分離\2_test\11
?????文件???????1946??2015-05-13?20:27??背景分離\2_test\test.cpp
?????文件??????83359??2015-05-13?19:55??背景分離\2_test\w.jpg
????..A..H.?????20480??2015-05-13?19:44??背景分離\opencv_example\.test.cpp.swp
?????文件??????38851??2015-05-13?19:42??背景分離\opencv_example\11
?????文件???????9200??2015-03-18?17:24??背景分離\opencv_example\grabcut.cpp
?????文件??????77384??2015-05-12?19:32??背景分離\opencv_example\grabcut.o
?????文件??????46786??2015-05-12?19:33??背景分離\opencv_example\test
?????文件???????5964??2015-05-13?19:44??背景分離\opencv_example\test.cpp
?????目錄??????????0??2015-05-14?09:11??背景分離\1_test
?????目錄??????????0??2015-05-14?09:11??背景分離\2_test
?????目錄??????????0??2015-05-14?09:11??背景分離\opencv_example
?????目錄??????????0??2015-05-14?09:11??背景分離
-----------?---------??----------?-----??----
???????????????930782????????????????????22
- 上一篇:opencv 車牌 字符識別
- 下一篇:線程和進/線程管道通信實驗操作系統實驗報告二
評論
共有 條評論