资源简介
对GrabCut算法讲解分析的很透彻,有文档,附带源码!运行绝对没有问题。
代码片段和文件信息
// WebProjectImage.cpp : 定义控制台应用程序的入口点。
//
#include “stdafx.h“
#include “opencv2/highgui/highgui.hpp“
#include “opencv2/imgproc/imgproc.hpp“
#include
#include
#include “math.h“
#include “highgui.h“
#include
using namespace std;
using namespace cv;
void help()
{
cout << “\nThis program demonstrates GrabCut segmentation -- select an object in a region\n“
“and then grabcut will attempt to segment it out.\n“
“Call:\n“
“./grabcut \n“
“\nSelect a rectangular area around the object you want to segment\n“ <<
“\nHot keys: \n“
“\tESC - quit the program\n“
“\tr - restore the original image\n“
“\tn - next iteration\n“
“\n“
“\tleft mouse button - set rectangle\n“
“\n“
“\tCTRL+left mouse button - set GC_BGD pixels\n“
“\tSHIFT+left mouse button - set CG_FGD pixels\n“
“\n“
“\tCTRL+right mouse button - set GC_PR_BGD pixels\n“
“\tSHIFT+right mouse button - set CG_PR_FGD pixels\n“ << endl;
}
const Scalar RED = Scalar(00255);
const Scalar PINK = Scalar(230130255);
const Scalar BLUE = Scalar(25500);
const Scalar LIGHTBLUE = Scalar(255255160);
const Scalar GREEN = Scalar(02550);
const int BGD_KEY = CV_EVENT_FLAG_CTRLKEY;
const int FGD_KEY = CV_EVENT_FLAG_SHIFTKEY;
//把comMask赋给binMak
void getBinMask( const Mat& comMask Mat& binMask )
{
if( comMask.empty() || comMask.type()!=CV_8UC1 )
CV_Error( CV_StsBadArg “comMask is empty or has incorrect type (not CV_8UC1)“ );
if( binMask.empty() || binMask.rows!=comMask.rows || binMask.cols!=comMask.cols )
//设置Mat大小★★★★
binMask.create( comMask.size() CV_8UC1 );
binMask = comMask & 1;//★★★★很重要
}
class GCApplication
{
public:
enum{ NOT_SET = 0 IN_PROCESS = 1 SET = 2 };
static const int radius = 2;
static const int thickness = -1;
void reset();
void setImageAndWinName( const Mat& _image const string& _winName );
void showImage() const;
void mouseClick( int event int x int y int flags void* param );
int nextIter();
int getIterCount() const { return iterCount; }
private:
void setRectInMask();
void setLblsInMask( int flags Point p bool isPr );
const string* winName;
const Mat* image;
Mat mask;
Mat bgdModel fgdModel;
uchar rectState lblsState prLblsState;
bool isInitialized;
Rect rect;
vector fgdPxls bgdPxls prFgdPxls prBgdPxls;
int iterCount;
};
void GCApplication::reset()
{
if( !mask.empty() )
//mask设定为GC_BGD,GC_FGD,GC_PR_BGD中的一种;
mask.setTo(Scalar::all(GC_BGD));
bgdPxls.clear(); fgdPxls.clear();
prBgdPxls.clear(); prFgdPxls.clear();
isInitialized = false;
rectState = NOT_SET;
lblsState = NOT_SET;
prLblsState = NOT_SET;
iterCount = 0;
}
void GCApplication::setImageAndWinNa
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10306 2013-10-10 20:40 WebProjectImage.cpp
文件 21730 2013-09-29 13:51 图像分割之(一)概述.docx
文件 210190 2013-09-29 21:17 图像分割之(三)从Graph Cut到Grab Cut.docx
文件 176327 2013-09-29 20:35 图像分割之(二)Graph Cut(图割).docx
文件 57335 2013-09-29 13:56 图像分割之(四)OpenCV的GrabCut函数使用和源码解读.docx
- 上一篇:非侵入式负载检测
- 下一篇:监控系统最全的CAD图块
相关资源
- NVIDIAOpticalFlowSDK-79c6cee80a2df9a196f20afd6
- opencv_contrib-3.4.0.zip
- opencv2.4.9源码分析——SIFT
- 用两个摄像头实现,双目标定,双目
- opencv_traincascade训练分类器,手势识别
- opencv3.0交叉编译用parallel.cpp
- 基于opencv的图像识别识别图像中的色
- 基于openCV的识别特定颜色区域
- 基于OpenCV的分水岭算法实现
- QT+opencv+OCR 身份证号码,银行卡号识别
- opencv视频特定颜色区域识别
- 把RGB转换为HSV和HSI然后根据黄色和蓝
- opencv视觉测距
- 基于Qt和opencv的身份证号码识别系统
- opencv_ffmpeg249.dll
- SfM稀疏三维点云重建--完整工程文件
- 基于opencv的数人头程序源代码
- 利用OpenCV中的Stitcher类实现全景图像拼
- opencv实现的sift算法源码,包含了图像
- openCV 上的小波变换
- 基于OPENCV的车牌识别系统设计
- 617张国内车牌60-17bmp图片用于OpenCV正样
- hog特征提取,c版本代码
- 基于Qt5.8+OpenCV3.2的Basler多相机触发开
- 基于Opencv实现的图像纠偏
- ImageWatch2019.vsix
- SIFT特征提取+匹配
- 基于SIFT算法的图像拼接.rar
- opencv4.1.1+contrib完整版.zip
- OpenCV3.3+contrib-master,VS2013编译后的l
评论
共有 条评论