資源簡介
積分最低,車標檢測,檢測輪廓出來,粗定位和精定位提取車標,基于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? {
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? {
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
- 上一篇:西門子plc三層電梯梯形圖
- 下一篇:labview的電池管理系統
評論
共有 條評論