Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

C # how to realize vehicle contour recognition

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how c # realizes vehicle outline recognition". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn the article "c # how to realize vehicle outline recognition".

Scene

The contour recognition of the vehicle has been realized, and the minimum rectangular range of the outline has been extracted. Now we need to know the two points closest to the rectangle at the rear of the car, which may be a bit overqualified.

Code

# include "opencv2/highgui/highgui.hpp"

# include "opencv2/imgproc/imgproc.hpp"

# include

Using namespace cv

Using namespace std

Void Dilate (InputArray src, OutputArray dst)

{

Int dilation_type = MORPH_RECT

Int dilation_size = 10

Mat dielem = getStructuringElement (dilation_type

Size (2*dilation_size+1, 2*dilation_size+1)

Point (dilation_size, dilation_size))

/ / expansion operation

Dilate (src, dst, dielem)

}

/ *

This function is mainly used to capture the complete outline of the vehicle in the picture, and the judgment condition is

The Y coordinate of the outline of the vehicle cannot be greater than the length of the picture, and secondly, the filtering area is too small.

The outline of the vehicle is likely to be the error caused by the mirror or the difference between frames to split the vehicle into two segments.

, /

Void CaptureCompleteVehicle (Mat & srcMat, Mat & grayMat)

{

Vector contours

Vector hierarchy

FindContours (grayMat, contours,hierarchy,RETR_EXTERNAL,CHAIN_APPROX_NONE,Point ())

Mat dstMat=Mat::zeros (grayMat.size (), CV_8UC1)

Mat contourMat

SrcMat.copyTo (contourMat)

Int picHeight = grayMat.size () .height

Bool bTouchBotton = false

Bool bTouchTop = false

Vector mu (contours.size ())

For (int iTuno; I > framePre)

CvtColor (framePrePre,framePrePre,CV_RGB2GRAY)

CvtColor (framePre,framePre,CV_RGB2GRAY)

Int save=0

While (true)

{

VideoCap > > frameNow

If (frameNow.empty ()) | | waitKey (videoPause) = = 27) break

CvtColor (frameNow,frameNow,CV_RGB2GRAY)

Mat Det1

Mat Det2

Absdiff (framePrePre,framePre,Det1); / / frame difference 1

Absdiff (framePre,frameNow,Det2); / / frame difference 2

Threshold (Det1,Det1,0,255,CV_THRESH_OTSU); / / Adaptive thresholding

Threshold (Det2,Det2,0,255,CV_THRESH_OTSU)

Mat element=getStructuringElement (0Magnum size (3je 3)); / / inflated kernel

Dilate (Det1,Det1,element); / / expansion

Dilate (Det2,Det2,element)

Bitwise_and (Det1,Det2,frameDet)

FramePrePre=framePre

FramePre=frameNow

Dilate (frameDet, frameDet)

CaptureCompleteVehicle (frameNow, frameDet)

WaitKey (1000)

}

Return 0

}

The above is all the contents of the article "how to realize vehicle outline recognition". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report