回答編集履歴
2
少しシンプルに
test
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
荒業ですが…
|
2
2
|
|
3
|
-
![イメージ説明](
|
3
|
+
![イメージ説明](89dee0e0f746f27d836ef513a9ac3b8f.png)
|
4
|
-
|
5
|
-
|
6
4
|
|
7
5
|
```Python3
|
8
6
|
|
@@ -10,37 +8,17 @@
|
|
10
8
|
|
11
9
|
import numpy as np
|
12
10
|
|
13
|
-
from scipy import ndimage as ndi
|
14
|
-
|
15
|
-
from skimage.feature import peak_local_max
|
16
|
-
|
17
11
|
|
18
12
|
|
19
13
|
img = cv2.imread('temp.jpeg',0)
|
20
14
|
|
21
15
|
# img = 255-img
|
22
16
|
|
23
|
-
img = cv2.medianBlur(img,11)
|
17
|
+
img_blur = cv2.medianBlur(img,11)
|
24
|
-
|
25
|
-
dist = ndi.distance_transform_edt(img)
|
26
|
-
|
27
|
-
dist = dist - np.min(dist)
|
28
|
-
|
29
|
-
dist[dist<0.1] = 0
|
30
|
-
|
31
|
-
dist = np.asarray(dist/np.max(dist)*255,np.uint8)
|
32
|
-
|
33
|
-
# cv2.imshow("dist",dist)
|
34
18
|
|
35
19
|
|
36
20
|
|
37
|
-
|
21
|
+
cv2.imshow('img_blur',img_blur)
|
38
|
-
|
39
|
-
img[dist<32] = 0
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
cv2.imshow('img (modified)',img)
|
44
22
|
|
45
23
|
|
46
24
|
|
@@ -48,7 +26,7 @@
|
|
48
26
|
|
49
27
|
|
50
28
|
|
51
|
-
circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,
|
29
|
+
circles = cv2.HoughCircles(img_blur,cv2.HOUGH_GRADIENT,1,2,param1=10,param2=8,minRadius=20,maxRadius=40)
|
52
30
|
|
53
31
|
|
54
32
|
|
@@ -56,9 +34,9 @@
|
|
56
34
|
|
57
35
|
for i in circles[0,:]:
|
58
36
|
|
59
|
-
print(img[int(i[1]),int(i[0])])
|
37
|
+
# print(img[int(i[1]),int(i[0])])
|
60
38
|
|
61
|
-
if 0 < img[int(i[1]),int(i[0])]:
|
39
|
+
if 0 < img_blur[int(i[1]),int(i[0])]:
|
62
40
|
|
63
41
|
# draw the outer circle
|
64
42
|
|
@@ -67,6 +45,14 @@
|
|
67
45
|
# draw the center of the circle
|
68
46
|
|
69
47
|
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
|
48
|
+
|
49
|
+
# else:
|
50
|
+
|
51
|
+
# cv2.circle(cimg,(i[0],i[1]),i[2],(0,64,0),1)
|
52
|
+
|
53
|
+
# cv2.circle(cimg,(i[0],i[1]),2,(0,0,64),1)
|
54
|
+
|
55
|
+
|
70
56
|
|
71
57
|
|
72
58
|
|
@@ -87,6 +73,10 @@
|
|
87
73
|
```
|
88
74
|
|
89
75
|
|
76
|
+
|
77
|
+
以下、初回投稿部分
|
78
|
+
|
79
|
+
---
|
90
80
|
|
91
81
|
|
92
82
|
|
1
「むしゃくしゃしてやった、後悔はしていない。」
test
CHANGED
@@ -1,3 +1,95 @@
|
|
1
|
+
荒業ですが…
|
2
|
+
|
3
|
+
![イメージ説明](365f2e76866c8712ba1ef3c267139fa4.jpeg)
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
```Python3
|
8
|
+
|
9
|
+
import cv2
|
10
|
+
|
11
|
+
import numpy as np
|
12
|
+
|
13
|
+
from scipy import ndimage as ndi
|
14
|
+
|
15
|
+
from skimage.feature import peak_local_max
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
img = cv2.imread('temp.jpeg',0)
|
20
|
+
|
21
|
+
# img = 255-img
|
22
|
+
|
23
|
+
img = cv2.medianBlur(img,11)
|
24
|
+
|
25
|
+
dist = ndi.distance_transform_edt(img)
|
26
|
+
|
27
|
+
dist = dist - np.min(dist)
|
28
|
+
|
29
|
+
dist[dist<0.1] = 0
|
30
|
+
|
31
|
+
dist = np.asarray(dist/np.max(dist)*255,np.uint8)
|
32
|
+
|
33
|
+
# cv2.imshow("dist",dist)
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
# cv2.imshow('img (blur)',img)
|
38
|
+
|
39
|
+
img[dist<32] = 0
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
cv2.imshow('img (modified)',img)
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,1,param1=10,param2=10,minRadius=10,maxRadius=40)
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
if circles is not None:
|
56
|
+
|
57
|
+
for i in circles[0,:]:
|
58
|
+
|
59
|
+
print(img[int(i[1]),int(i[0])])
|
60
|
+
|
61
|
+
if 0 < img[int(i[1]),int(i[0])]:
|
62
|
+
|
63
|
+
# draw the outer circle
|
64
|
+
|
65
|
+
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
|
66
|
+
|
67
|
+
# draw the center of the circle
|
68
|
+
|
69
|
+
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
cv2.imshow('detected circles',cimg)
|
74
|
+
|
75
|
+
else:
|
76
|
+
|
77
|
+
print("No circles detected.")
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
cv2.waitKey(0)
|
82
|
+
|
83
|
+
cv2.destroyAllWindows()
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
1
93
|
> 最終面積が一番大きいところを取得する予定
|
2
94
|
|
3
95
|
> 画像は目を二値化したもので、黒目の部分だけ抽出したいです。
|