【发布时间】:2016-05-09 20:37:49
【问题描述】:
我使用 OpenCV 和 Houghlines(在 c++ 中)制作了一条蓝线,我想知道在 if 语句中应该包含什么来检测蓝线是否存在以及它是否确实执行了操作。
我尝试使用 cv::inRange 函数来检测蓝色,但我无法在 if 语句中使用它。
这是绘制蓝线的代码:
vector<Vec2f> lines;
HoughLines(dst, lines, 1, CV_PI/180, 100, 0, 0 );
for(size_t i = 0;i < lines.size();i++)
{
float rho = lines[i][0], theta = lines[i][1];
//scan only for horizontal line)
if(theta > CV_PI/180*80 && theta < CV_PI/180*100){
Point pt1, pt2;
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
pt1.x = cvRound(x0 + 1000*(-b));
pt1.y = cvRound(y0 + 1000*(a));
pt2.x = cvRound(x0 - 1000*(-b));
pt2.y = cvRound(y0 - 1000*(a));
//draw the line in blue
cvLine(m_image, pt1, pt2, Scalar(255,0,0), 3, CV_AA);
}
}
}
基本上我想做的是
if (blue line exists) {
do something
}
这是我得到的当前图像。 (忽略绿线和红线,它基本上是路上汽车的POV)我想检测蓝线何时进入图像的下部(在图片的正前方)然后执行动作(使汽车停止)
感谢您的宝贵时间。
PS。谢谢Saransh Kejriwal,我现在正在尝试使用国旗。
【问题讨论】:
-
最终图像会是什么样子?除了画线的位置之外,图像是否可以在像素处具有相似的颜色?
-
我添加了正在分析的图片,谢谢!