• 大小: 1KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-25
  • 语言: 其他
  • 标签: 车标检测  opencv  

资源简介

积分最低,车标检测,检测轮廓出来,粗定位和精定位提取车标,基于vs2013+opencv的方法

资源截图

代码片段和文件信息

#include “cv.h“    
#include “highgui.h“    
#include    

#include 
#include

using namespace std;
using namespace cv;

Mat src;
Mat  src_gray;
int thresh = 100;
int max_thresh = 255;
RNG rng(12345);

void thresh_callback(int void*);

int main(int argc char** argv)
{
src = imread(“1.jpg“ 1);

cvtColor(src src_gray CV_BGR2GRAY);
blur(src_gray src_gray Size(3 3));

char* source_window = “Source“;
namedWindow(source_window CV_WINDOW_AUTOSIZE);
imshow(source_window src);

createTrackbar(“Threshold:“ “Source“ &thresh max_thresh thresh_callback);
thresh_callback(0 0);

waitKey(0);
return 0;

}

void thresh_callback(int void*)
{

Mat threshold_output;
vector> contours;
vector hierarchy;
//Canny(src_gray canny_Mat thresh thresh * 2 3);
/// 使用Threshold检测边缘  
threshold(src_gray threshold_output thresh 255 THRESH_BINARY);
findContours(threshold_output contours hierarchyCV_RETR_TREECV_CHAIN_APPROX_SIMPLE Point(0 0));

/// 多边形逼近轮廓 + 获取矩形和圆形边界框  
vector>contours_poly(contours.size());
vector bondRect(contours.size());
vectorcenter(contours.size());
vectorradius(contours.size());


vector>::iterator iter = contours.begin();
for (int i = 0; i < contours.size(); i++)
{
approxPolyDP(Mat(contours[i]) contours_poly[i] 3 true);
bondRect[i] = boundingRect(Mat(contours[i]));
minEnclosingCircle(contours[i] center[i] radius[i]);
}

/// 画多边形轮廓 + 包围的矩形框 + 圆形框  
Mat drawing = Mat::zeros(threshold_output.size() CV_8UC3);
for (int i = 0; i < contours.size(); i++)
{
Scalar color = Scalar(rng.uniform(0 255) rng.uniform(0 255) rng.uniform(0 255));
drawContours(src contours i color 1 8 hierarchy 0 Point());
drawContours(drawing contours_poly i color 1 8 vector() 0 Point());
if (bondRect[i].area() > 50 && bondRect[i].width < 50 && bondRect[i].height < 50)
{
rectangle(drawing bondRect[i].tl() bondRect[i].br() color 2 8 0);
// circle(drawing center[i] (int)radius[i] color 2 8 0);
}

}
namedWindow(“contours“ CV_WINDOW_AUTOSIZE);
imshow(“contours“ drawing);
namedWindow(“contours_src“ CV_WINDOW_AUTOSIZE);
imshow(“contours_src“ src);

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        2421  2018-05-09 21:00  vehicle detecting.cpp

评论

共有 条评论