场景
我想用resize函数缩小图像的大小,减少车辆上无关的颜色,比如车牌,比如后视镜,或者出租车车顶。 我想戴上相关的细节来画车辆的轮廓。 结果没有收到任何效果,contour没有实现连接性的关闭
代码
#包含
#包含
#包含
用户命名空间STD;
using namespace cv;
(intmain(intargc,char* argv[] ) ) ) ) ) ) ) ) ) ) )
{
int resize_height=256;
int resize_width=256;
cv : mat src=cv :3360 im read (d :/2017060109226.png ',0 );
Size srcSize=src.size (;
resize_height= srcSize.height/5;
resize_width= srcSize.width/5;
cv:Mat dst;
imshow(src )、src );
cv:3360resize(src,dst,cv:3360size ) resize_width,resize_height ),0,0,cv:INTER_LINEAR
imshow(dst )、dst );
Mat p_w_picpath;
threshold(dst,dst,100,255,CV_THRESH_BINARY );
Gussianblur(dst,p_w_picpath,size (3,3 ),0 );
canny(p_w_picpath,p_w_picpath,100,250 );
imshow(cannyimage )、p_w_picpath );
向量内容;
向量层次;
findcontours(p_w_picpath,contours,hierarchy,RETR_EXTERNAL,CHAIN_APPROX_SIMPLE );
matp _ w _ picpath contours=mat :3360 zeros (p _ w _ picpath.size (,CV_8UC1 );
for(intI=0; I
{
if(contourarea(contours[I] ) 50 ) continue;
draw contours (p _ w _ picpath contours,contours,I,scalar ) 255 )、1、8、hierarchy );
rect r0=边界rect (mat (contours [ I ] ); //boundingRect取得该外接矩形
Rectangle(dst,r0,Scalar ) 255,255,0 ),2 );
}
imshow(contoursimage ),p_w_picpathContours );
cv :3360等待密钥(0;
返回0;
}