質問編集履歴
1
エラーコードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -53,3 +53,61 @@
|
|
53
53
|
https://docs.opencv.org/3.1.0/dd/d49/tutorial_py_contour_features.html
|
54
54
|
|
55
55
|
しかし、私はプログラムの勉強を始めて間もないため、どのようにプログラムに組み込めばよいかわからず、どのようにしてもエラーが出てしまいます。実装の仕方を教えていただきたいです。
|
56
|
+
|
57
|
+
以下にエラーが出るコードを示します。
|
58
|
+
|
59
|
+
```python
|
60
|
+
|
61
|
+
import numpy
|
62
|
+
|
63
|
+
import cv2
|
64
|
+
|
65
|
+
cap = cv2.VideoCapture(0)
|
66
|
+
|
67
|
+
while True:
|
68
|
+
|
69
|
+
ret, frame = cap.read()
|
70
|
+
|
71
|
+
gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
|
72
|
+
|
73
|
+
gray = cv2.GaussianBlur(gray, (33,33), 1)
|
74
|
+
|
75
|
+
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 60, param1=10, param2=85, minRadius=10, maxRadius=80)
|
76
|
+
|
77
|
+
if circles is not None:
|
78
|
+
|
79
|
+
circles = np.uint16(np.around(circles))
|
80
|
+
|
81
|
+
for i in circles[0,:]:
|
82
|
+
|
83
|
+
M = cv2.circle(frame,(i[0],i[1]),i[2],(255,255,0),2)
|
84
|
+
|
85
|
+
cv2.circle(frame,(i[0],i[1]),2,(0,0,255),3)
|
86
|
+
|
87
|
+
area = cv2.contourArea(M)
|
88
|
+
|
89
|
+
print(area)
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
cv2.imshow('preview', frame)
|
94
|
+
|
95
|
+
key = cv2.waitKey(10)
|
96
|
+
|
97
|
+
if key == ord("q"):
|
98
|
+
|
99
|
+
break
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
cv2.destroyAllWindows()
|
104
|
+
|
105
|
+
コード
|
106
|
+
|
107
|
+
```
|
108
|
+
|
109
|
+
エラー内用は以下に示す通りです。
|
110
|
+
|
111
|
+
area = cv2.contourArea(M)
|
112
|
+
|
113
|
+
cv2.error: ..¥..¥..¥modules¥imgproc¥src¥shapedescr.cpp:314: error: (-215) npoints >= 0 && (depth == CV_32) in function cv::contourArea
|