资源简介
Graphcut-源码及实现,基于opencv实现。可直接运行,其中鼠标左右键分别用于选择正、负种子点。
代码片段和文件信息
#include
#include “gcgraphMy.h“
#include “opencv2/highgui/highgui.hpp“
#include “opencv2/imgproc/imgproc.hpp“
#include
using namespace std;
using namespace cv;
/*
This section shows how to use the library to compute
a minimum cut on the following graph :
*/
///////////////////////////////////////////////////
#include
const int nDownSample = 1;
const Scalar RED = Scalar(0 0 255);
const Scalar PINK = Scalar(230 130 255);
const Scalar BLUE = Scalar(255 0 0);
const Scalar LIGHTBLUE = Scalar(255 255 160);
const Scalar GREEN = Scalar(0 255 0);
#define MASK_BG_COLOR 128
#define MASK_FG_COLOR 255
const Scalar FG_MASK_COLOR = Scalar(255 255 255);
const Scalar BG_MASK_COLOR = Scalar(128 128 128);
const int BGD_KEY = CV_EVENT_FLAG_CTRLKEY;
const int FGD_KEY = CV_EVENT_FLAG_SHIFTKEY;
static 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)
binMask.create(comMask.size() CV_8UC1);
binMask = comMask & 1;
}
static void showImageS2(const Mat& image const string& winName)
{
cvResizeWindow(winName.c_str() image.cols / nDownSample image.rows / nDownSample);
imshow(winName image);
}
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(int x int y int FgPoint);
void mouseClick(int event int x int y int flags void* param);
void graphConstruct(const Mat& img GCGraphMy& graph);
void estimateSegmentation(GCGraphMy& graph);
int nextIter();
int getIterCount() const { return iterCount; }
void calSeedPHist(const Mat& img const Mat& mask);
private:
void setRectInMask();
void fillSeedToMask(Mat& mask);
void setLblsInMask(int x int y bool isFg);
double calFgdPrioriCost(Vec3b &color);
double calBgdPrioriCost(Vec3b &color);
const string* winName;
const Mat* image;
Mat mask;
Mat imgShowPg;
Mat bgdModel fgdModel;
double FgPHist[3][256];
double BgPHist[3][256];
double gamma;
double lambda;
double beta;
Mat leftW upleftW upW uprightW;
GCGraphMy graphMy;
uchar rectState lblsState prLblsState;
bool isInitialized;
Rect rect;
vector fgdPxls bgdPxls prFgdPxls prBgdPxls;
int iterCount;
};
void GCApplication::reset()
{
if (!mask.empty())
{
mask.setTo(Scalar::all(GC_BGD));
namedWindow(“mask“ 0);
}
bgdPxls.clear(); fgdPxls.clear();
prBgdPxls.clear(); prFgdPxls.clear();
this->im
- 上一篇:手机虚拟示波器
- 下一篇:网易云音乐器.zip
相关资源
- 冈萨雷斯 数字图像处理 源代码(m文
- qt图像处理
- 基于OpenCV的数字识别468815
- 血液图像处理—细胞识别
- VC数字图像处理课程设计
- 图像处理作业C 源代码
- SAR图像处理1
- Graphics Magic图像处理魔术师,含Delph
- 铝合金方波交流TIG焊熔池图像处理
- 带式输送机托辊红外图像分割与定位
- 基于图像处理的智能车寻迹算法设计
- 医学超声图像处理研究+哈尔滨工业大
- 基于libsvm的图像分割代码
- 友锋图像处理系统v3.rar(破解版
- 图像处理代码
- 图片-视频互换程序
- 基于图论的图像处理
- opencv视觉测距
- 北京交通大学-数字图像处理试卷+ 答
- 数字图像处理 王伟强 国科大 期末试
- 国科大图像处理作业王伟强老师.rar
- 国科大数字图像处理习题课重点
- 数字图像处理标准测试图片335张
- 哈尔滨工业大学深圳 数字图像处理
- 东南大学数字图像处理期末复习
- 2019国科大 王伟强 课程PPT+作业+中文翻
- 国科大图像处理期末考题2017(王伟强
- 数字图像处理课程设计 实验报告
- 国科大王伟强图像处理期末考试2018
- 国科大-图像处理与分析-2018期末试题
评论
共有 条评论