使用轮廓检测​​汽车

时间:2020-05-20 00:00:29

标签: object-detection detection contour

嗨,我正在尝试开发一个代码(如下),以使用轮廓检测​​汽车,但问题是我的图像质量太低,轮廓显得稀疏,无法让我检测到使用近似值的汽车,我只是附加了原始图像的链接。 你有什么建议?

import numpy as np
import cv2 as cv
img2=cv.imread('9.bmp')
from PIL import Image
Image.open("9.bmp").save("sample1.jpg")
img2=cv.imread('sample1.jpg')


img = cv.detailEnhance(img2, sigma_s=300, sigma_r=0.10)


imggray=cv.cvtColor(img,cv.COLOR_BGR2GRAY)
blurred = cv.GaussianBlur(imggray, (1,1), 0)
edged = cv.Canny(blurred, 999, 3,True)
_,thresh3 = cv.threshold(edged,254,255,cv.THRESH_TRUNC)

contours,_=cv.findContours(thresh3,cv.RETR_TREE,cv.CHAIN_APPROX_SIMPLE)

cv.drawContours(img,contours,-1,(0,255,0),1)

#for contour in contours:
#
#    approx=cv.approxPolyDP(contour,0.0001*cv.arcLength(contour,True),True)
#    (x, y, w, h) = cv.boundingRect(approx)
#    area = cv.contourArea(contour)
#    ar=float(w)/h
#    if area<=600 and float(w)<100 and float(w)>5 and ar<=10:
#       cv.drawContours(img,[approx],-1,(0,0,255),1)

original

0 个答案:

没有答案