我有一把黑色剪刀(下图),我想计算它的角度。角度介于180和0.之间。我使用cv2.line()
得到两条线进行角度计算,但我只能检测到天使,如果它的180或0.how我能找到一个" > "有轮廓的形状?(手柄也是黑色)
#Decapitary
import cv2
import numpy as np
import cv2.cv as cv
import math
import sys
cap = cv2.VideoCapture(0)
max_area =0
while(1):
# Take each frame
_, frame = cap.read()
# Convert BGR to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower_black = np.array([0,0,0])
upper_black = np.array([180,255,30])
mask= cv2.inRange(hsv, lower_red, upper_red)
mask = cv2.GaussianBlur(mask,(1,1),2)
mask = cv2.dilate(mask, np.ones((7,7),np.uint8))
mask = cv2.erode(mask, np.ones((5,5),np.uint8))
edges = cv2.Canny(mask,thresh,thresh*5)
contours, hierarchy = cv2.findContours(edges,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) ### use this to calculte the angel.
for c in contours:
area = cv2.contourArea(c)
if area > max_area:
max_area = area
yu = c
nss = np.asarray(yu,dtype=np.int32)
cv2.polylines(frame, [nss], 0 , (0,0,250))
cv2.imshow('frame',frame)
cv2.imshow('edges',edges)
cv2.imshow('mask',mask)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
我愿意接受各种想法,真的需要帮助。请告诉我正确的方向
编辑:
我可以训练一个级联来找到一个物体的特定点(在这种情况下,边缘上的3个点来计算天使)???