【发布时间】:2014-08-15 17:45:47
【问题描述】:
我知道整个网络上有一百个关于我的问题的主题,但我想针对我的问题提出具体的问题,因为我尝试了几乎所有的解决方案,但都没有成功。
我正在尝试计算图像中的圆圈(是的,我已经尝试过霍夫圆圈,但由于光反射,我认为我的对象不是很健壮)。 然后我尝试创建一个分类器(没有成功我认为没有足够的特征所以检测不好)
我也尝试过 HSV 对话并尝试找到我的颜色对象(由于光线和颜色的变化,我再次遇到了一些问题) 正如您在图片上看到的,有 8 个大写字母,我希望能够数一数。
使用所有这些方法,我能够检测到图像上的对象(因为我正在优化特定图像的所有函数参数)但是一旦我加载了一个新的、相似的图像,结果令人失望.
请点击此链接查看Image
您可以在下面找到我尝试过的所有内容的一部分:
1.霍夫圆
img = cv2.imread('frame71.jpg',1)
img = cv2.medianBlur(img,5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
if img == None:
print "There is no image file. Quiting..."
quit()
circles = cv2.HoughCircles(img,cv.CV_HOUGH_GRADIENT,3,50,
param1=55,param2=125,minRadius=25,maxRadius=45)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
print len(circles[0,:])
cv2.imshow('detected circles',cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()
2。 HSV 变换、颜色检测
def image_process(frame, h_low, s_low, v_low, h_up, s_up, v_up, ksize):
temp = ksize
if(temp%2==1):
ksize = temp
else:
ksize = temp+1
#if(True):
# return frame
#thresh = frame
#try:
#TODO: optimize as much as possiblle this part of code
try:
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower = np.array([h_low, s_low, v_low],np.uint8)
upper = np.array([h_up,s_up,h_up],np.uint8)
mask = cv2.inRange(hsv, lower, upper)
res = cv2.bitwise_and(hsv,hsv, mask= mask)
thresh = cv2.cvtColor(res, cv2.COLOR_BGR2GRAY)
#thresh = cv2.threshold(res, 50, 255, cv2.THRESH_BINARY)[1]
thresh = cv2.threshold(thresh, 50, 255, cv2.THRESH_BINARY)[1]
thresh = cv2.medianBlur(thresh,ksize)
except Exception as inst:
print type(inst)
#cv2.imshow('thresh', thresh)
return thresh
3.级联分类器
img = cv2.imread('frame405.jpg', 1)
cap_cascade = cv2.CascadeClassifier('haar_30_17_16_stage.xml')
caps = cap_cascade.detectMultiScale(img, 1.3, 5)
#print caps
for (x,y,w,h) in caps:
cv2.rectangle(img, (x,y), (x+w,y+h), (255,0,0),2)
#cv2.rectangle(img, (10,10),(100,100),(0,255,255),4)
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
quit()
关于训练分类器,我确实使用了很多不同的图像、样本、负例和正例、阶段数、w 和 h,但结果不是很准确。
最后,我想根据您的经验了解我应该遵循的最佳方法,我会坚持下去以优化我的检测。请记住,所有图像都是相似的,但并不完全相同。由于光线,运动等原因存在一些差异
比你提前,
【问题讨论】:
-
您可以访问图像还是访问视频源?如果是视频,你应该能够通过瓶子的运动来分割瓶子,然后对提取的区域进行进一步的处理。
-
瓶子的流量是恒定的,但我在凸轮下方的时候拍照。
-
添加我尝试使用颜色查找帽子的那一刻,我认为问题在于帽子上方的透明尼龙。我用另一个图像测试我的代码,我能够隐藏图像中除颜色之外的所有其他内容,但是正如你在图像中看到的那样,我无法做到这一点。 HSV 的范围设置为最大值和最小值,但黄色被排除在外!图片:dl.dropboxusercontent.com/u/5502709/te.png
-
@user2117118 您找到了任何解决此问题的方法。我也面临同样的问题。
标签: opencv object colors geometry detection