sky*_*awk 5 android opencv traffic detection hsv
我在使用opencv 2.4 for Android检测速度交通标志时遇到问题.我做以下事情:
"捕获帧 - >将其转换为HSV - >提取红色区域 - >检测带椭圆检测的符号"
到目前为止,只要图像质量好,椭圆检测就能完美.但正如你在图片中看到的那样,红色提取不能正常工作,因为相框质量差,我认为.
将原始图像转换为HSV:
Imgproc.cvtColor(this.source, this.source, Imgproc.COLOR_RGB2HSV, 3);
Run Code Online (Sandbox Code Playgroud)
提取红色:
Core.inRange(this.source, new Scalar(this.h,this.s,this.v), new Scalar(230,180,180), this.source);
Run Code Online (Sandbox Code Playgroud)
所以我的问题是有另一种方法来检测这样的交通标志或从中提取出红色区域,顺便说一句,这可能会像上一张图片一样微弱吗?
这是原始图片:
这被转换为HSV,因为您可以看到红色区域看起来与附近的树木颜色相同.多数民众赞成我怎么想知道它是红色但我不能.
转换为HSV:
这是用红色提取的.如果颜色是正确的,我应该在符号周围得到几乎完美的圆/椭圆,但由于错误的颜色,它是不完整的.
提取后的结果:
椭圆法:
private void findEllipses(Mat input){
Mat thresholdOutput = new Mat();
int thresh = 150;
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
MatOfInt4 hierarchy = new MatOfInt4();
Imgproc.threshold(source, thresholdOutput, thresh, 255, Imgproc.THRESH_BINARY);
//Imgproc.Canny(source, thresholdOutput, 50, 180);
Imgproc.findContours(source, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
RotatedRect minEllipse[] = new RotatedRect[contours.size()];
for(int i=0; i<contours.size();i++){
MatOfPoint2f temp=new MatOfPoint2f(contours.get(i).toArray());
if(temp.size().height > minEllipseSize && temp.size().height < maxEllipseSize){
double a = Imgproc.fitEllipse(temp).size.height;
double b = Imgproc.fitEllipse(temp).size.width;
if(Math.abs(a - b) < 10)
minEllipse[i] = Imgproc.fitEllipse(temp);
}
}
detectedObjects.clear();
for( int i = 0; i< contours.size(); i++ ){
Scalar color = new Scalar(180, 255, 180);
if(minEllipse[i] != null){
detectedObjects.add(new DetectedObject(minEllipse[i].center));
DetectedObject detectedObj = new DetectedObject(minEllipse[i].center);
Core.ellipse(source, minEllipse[i], color, 2, 8);
}
}
Run Code Online (Sandbox Code Playgroud)
}
您将看到有两种方法可以实现此目的:
根据我的经验,我发现基于形状的方法效果很好,因为在不同的光照条件,相机质量等下,颜色可能会发生很大变化.
由于您需要检测速度交通标志,我认为它总是圆形的,您可以使用椭圆检测器查找图像中的所有圆形对象,然后应用一些验证来确定它是否是交通标志.
为什么椭圆检测?
好吧,因为你正在寻找透视扭曲的圆圈,你实际上在寻找椭圆.实时椭圆检测是一个有趣(虽然有限)的研究课题.我将向您指出2篇可用C++源代码的论文(您可以通过本机JNI调用在您的app中使用):
L. Libuda,I.Grothues,K.-F.Kraiss,使用几何特征在数字图像数据中检测椭圆,见:J.Braz,A.Ranchordas,H.Arajo,J.Jorge(编辑),计算机图形学与计算机视觉进展,计算机与信息通信第4卷Science,Springer Berlin Heidelberg,2007,pp.229-239.链接,代码
M. Fornaciari,A.Prati,R.Cucchiara,"用于嵌入式视觉应用的快速有效的椭圆探测器",模式识别,2014年链接,代码
UPDATE
我尝试了方法2),没有任何预处理.您可以看到至少检测到带有红色边框的标志非常好:
| 归档时间: |
|
| 查看次数: |
5686 次 |
| 最近记录: |