博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
opencv入门笔记之三 简单图像识别,识别线,点,圆,轮廓
阅读量:5093 次
发布时间:2019-06-13

本文共 2961 字,大约阅读时间需要 9 分钟。

Edge detection

int main(){

IplImage* girl = cvLoadImage(“road.jpg”, 0);
// convert color to grag
Mat boy;
//*************start******************************///
Mat cow = Mat(girl);
//Mat() convert IplImage to Mat
imshow(“cow”, cow);
Canny(cow, boy, 125, 350);
//125< |pixel - pixel| <350 (hysteresis thresholding)
imshow(“boy”, boy);
Mat Inv;
threshold(boy, Inv, 128, 255, THRESH_BINARY_INV);
// invert color
//*****************end**************************///
duration = static_cast(getTickCount()) - duration;
duration /= getTickFrequency();
cout << duration;
//
imshow(“Inv”, Inv);
waitKey(0);

}

2/5/2015 10:12 AM - Screen Clipping

Lines detection

Mat boundless = Mat(cvLoadImage(“road.jpg”, 0));
//convert color to grey
Mat bound;
Canny(boundless, bound, 125, 350);
vector lines;
HoughLines(bound, lines, 1, M_PI / 180, 80);
// if u wanna use PI there must be a #define _USE_MATH_DEFINES before math.h
vector::const_iterator it = lines.begin();
while (it != lines.end()){
float rho = (*it)[0];
float theta = (*it)[1];
if (theta < M_PI_4||theta>3*M_PI_4)
{
Point pt1(rho / cos(theta), 0);
Point pt2(rho - bound.rows*sin(theta) / cos(theta), bound.rows);
line(boundless,pt1, pt2, Scalar(255), 1);
}
else
{
Point pt1(0, rho / sin(theta));
Point pt2(bound.cols, rho - bound.cols*cos(theta) / sin(theta));
line(boundless, pt1, pt2, Scalar(255), 1);
}
++it;
}
imshow(“new”, boundless);

Probabilistic Hough transform

class findline
{
public:
findline() :deltarho(1), deltatheta(M_PI / 180), minvote(10), minlength(0.), maxGap(0.){}
// ~findline();
void setAccResolution(double rho=1, double theta=M_PI/180){
deltatheta = theta;
deltarho = rho;
}// smaller deltatheta and deltarho means more time and more precise
void setMinVote(int minv){
minvote = minv;
}// more votes, less lines
void setLineLengthAndGap(double length, double gap){
minlength = length;
maxGap = gap;
}// gap between lines and length of lines
vector findLines(Mat& binary){
lines.clear();
HoughLinesP(binary, lines, deltarho, deltatheta, minvote, minlength, maxGap);
return lines;
} //use probabilistic hough transform
void drawDetectedLines(Mat &image, Scalar color=Scalar(255,255,255)){
vector::const_iterator it2 = lines.begin();
while(it2 != lines.end()){
Point pt1((*it2)[0], (*it2)[1]);
Point pt2((*it2)[2], (*it2)[3]);
line(image, pt1, pt2, color);
++it2;
}
}// use const_iterator to draw lines

private:

Mat image;
vector lines;
double deltarho, deltatheta;
int minvote;
double minlength;
double maxGap;
};

void m(){

findline finder;
finder.setMinVote(80);
finder.setLineLengthAndGap(100, 20);
Mat image = imread(“ground.jpg”);
Mat coutours = Mat(cvLoadImage(“ground.jpg”, 0));
Canny(coutours, coutours, 125, 350);
// imshow(“hen”, coutours);
vector lines = finder.findLines(coutours);
finder.drawDetectedLines(image,Scalar(0,0,0));
imshow(“Hough”, image);
imwrite(“ok.jpg”, image);
}

vector

posted on
2015-02-05 20:59 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/Pomodori/p/4316620.html

你可能感兴趣的文章
局域网从另一台电脑copy文件(Linux系统下)
查看>>
FC和SCSI
查看>>
VC2010常见问题的解决方案
查看>>
超级详细Tcpdump 的用法
查看>>
程序员的思维修炼
查看>>
display:none和visibility:hidden的区别
查看>>
HDOJ---1232 畅通工程[并查集]
查看>>
Python学习路程-常用设计模式学习
查看>>
[JOYOI1326] 剑人合一
查看>>
[JZOJ100047] 【NOIP2017提高A组模拟7.14】基因变异
查看>>
梦断代码阅读笔记01
查看>>
利用“Java同包同名类执行顺序”取消Java 网站应用程序Licence验证
查看>>
UNICODE与ASCII码的关系(MTK)
查看>>
underscore源码学习笔记(一)
查看>>
iOS项目开发实战——通过Http Get方式与server通信
查看>>
ES6 Number
查看>>
Java基础学习-IO流
查看>>
TFS 2017 持续集成速记
查看>>
SVN客户端下载和Svn visual studio插件
查看>>
定义的form,宏等双击提示不存在的…
查看>>