【视觉】OpenCV探索之路:如何去除票据上的印章
机械人的蓝海,机器人的世界,
本文作者:CSDN 博客园 Madcola
原文网址:https://www.cnblogs.com/skyfsm/category/1000207.html?page=1
对彩色图分离通道,拿到红色通道图
进行阈值分割
#include 'opencv2/highgui.hpp'
using namespace cv;
int main()
{
Mat src = imread('100.bmp');
//resize(src, src, Size(700, 500));
Mat gray;
cvtColor(src, gray, CV_RGB2GRAY);
if (src.empty())
{
printf('fail to open image!\n');
return -1;
}
// 全局二值化
int th = 180; //阈值要根据实际情况调整
Mat binary;
threshold(gray, binary, th, 255, CV_THRESH_BINARY);
vectorchannels;
split(src, channels);
Mat red = channels[2];
Mat blue = channels[0];
Mat green = channels[1];
Mat red_binary;
threshold(red, red_binary, th, 255, CV_THRESH_BINARY);
imshow('src', src);
imshow('gray', gray);
imshow('binary', binary);
imshow('red channel', red);
imshow('blue channel', blue);
imshow('green channel', green);
imshow('red+binary', red_binary);
waitKey();
return 0;
}