我正在使用Python和OpenCV。我试图找到电池的中心和角度:如何查找图像中物体的中心和角度?
Image of batteries with random angles:
比我的代码是这样的:
import cv2
import numpy as np
img = cv2.imread('image/baterias2.png')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
img2 = cv2.imread('image/baterias4.png',0)
minLineLength = 300
maxLineGap = 5
edges = cv2.Canny(img2,50,200)
cv2.imshow('Canny',edges)
lines = cv2.HoughLinesP(edges,1,np.pi/180,80,minLineLength,maxLineGap)
print lines
salida = np.zeros((img.shape[0],img.shape[1]))
for x in range(0, len(lines)):
for x1,y1,x2,y2 in lines[x]:
cv2.line(salida,(x1,y1),(x2,y2),(125,125,125),0)# rgb
cv2.imshow('final',salida)
cv2.imwrite('result/hough.jpg',img)
cv2.waitKey(0)
任何想法去解决它?
你试过了什么? – saul
你好。我正在尝试这个步骤:1.门槛,2. Canny,3.线条,但显示我不完整的线条。 –
请分享您使用过的代码以及当前的输出结果吗? – ZdaR