[英]python, openCv, chain code -> i would like to find angles between the points
I'm new here and i need your HELP !!!! 我是新来的,需要您的帮助!!!! I'm making a project (hand gesture recognition for my school), so the image which is imread is my hand.
我正在做一个项目(我学校的手势识别),所以被读的图像就是我的手。 I'm would like to find angles between the points ( in chain code )
我想找到点之间的角度(在链代码中)
Thank you in advance :) 先感谢您 :)
import cv2
import cv2.cv as cv
import numpy as np
# Create display windows
cv2.namedWindow("input", cv.CV_WINDOW_AUTOSIZE)
cv2.namedWindow("output", cv.CV_WINDOW_AUTOSIZE)
# Parameters
blur_ksize = 5
thresh_Tlower = 100
kernel = np.ones((5,5),np.uint8)
# Imread the image
img = cv2.imread ("0_dani_mask.png",0)
# Funding the contours of the hand
contours, hierarchy = cv2.findContours(img.copy(), cv2.RETR_TREE, cv.CV_CHAIN_APPROX_NONE)
# contour = the biggest (area)
big_contour = contours[0]
num_points_cnt = len( big_contour )
print "num_points_cnt = ", num_points_cnt
theta = np.zeros( num_points_cnt, np.uint8 )
P0 = big_contour[0]
x0 = P0[0,0]
y0 = P0[0,1]
for n in range( 1, num_points_cnt ):
P = big_contour[n]
x = P[0,0]
y = P[0,1]
dX = x - x0
dY = y - y0
angulo = np.arctan( dY/dX )
theta[n] = angulo
x0 = x
y0 = y
P = big_contour[0]
x = P[0,0]
y = P[0,1]
dX = x - x0
dY = y - y0
angulo = np.arctan(dY/dX)
theta[0] = angulo
print theta
The program tells me that : 该程序告诉我:
num_points_cnt = 2031 [0 0 0 ..., 0 0 0] /Users/dani/Desktop/myproject/src/kasksasa.py:47: RuntimeWarning: divide by zero encountered in int_scalars angulo = np.tanh( dY/dX )
num_points_cnt = 2031 [0 0 0 ...,0 0 0] /Users/dani/Desktop/myproject/src/kasksasa.py:47:RuntimeWarning:除以int_scalars中遇到的零angulo = np.tanh(dY / dX)
To find the angle given dY
and dX
, use numpy.arctan2(dY, dX)
. 要找到给定
dY
和dX
的角度,请使用numpy.arctan2(dY, dX)
。 It handles dX = 0
correctly. 它正确处理
dX = 0
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.