简体   繁体   中英

Calculate car width from images using Python

I am trying to estimate the dimensions (width in this case) of car from images. I have 3 different images (with different angles) shown below. I have used the basic stuff to determine the canny edges of the images and the results are also shown in the images below. Here is my basic code for each car:

file = 'image.jpg'
img = cv2.imread(file, cv2.IMREAD_COLOR)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
bilateral = cv2.bilateralFilter(gray, 9, 75, 75)
canny = cv2.Canny(bilateral, 50, 255)
cv2.imshow('Canny Image', canny)
cv2.waitKey(0)

不同角度的原图

精明的图像结果

Now if I detect corners by using cv2.goodFeaturesToTrack() and cv2.cornerHarris() , the below image shows that I am getting very weird results shown in blue dots. 在此处输入图片说明

I studied that if we want to calculate the dimensions of object from 2D images we need at least 2 images just like our eye. Now, with the given scenario how can I find the width of the car (that is real world distance from left corner of the back light to the right corner of the back light) ? I have distance from camera to the car and also have distance between the each camera position. Also, please let me know if such (or related) work already exist as open source in python or any other language ? Thanks.

you are using traditional CV algorithm which wont solve your problem since your corners will be accurate in plane background.
what i would recommend you is use 2D object detection algorithms, from there you will get height & width of the object in image space ie pixel length.
To the obtained width in world space , use camera calibration transformation etc.

this answer can possibly help you. https://stackoverflow.com/questions/13419605/how-to-map-xy-pixel-to-world-cordinates#:~:text=1%20Answer&text=If%20you%20have%20x%2Cy,then%20by%20your%20z_world%20coordinate .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM