Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions Canny.py

This file was deleted.

50 changes: 50 additions & 0 deletions approximate_circle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import cv2
import numpy as np

img = cv2.imread("images/CIMG4555.JPG")

gau = cv2.GaussianBlur(img, (21, 21), 0)

gray = cv2.cvtColor(gau, cv2.COLOR_BGR2GRAY)

ret, th = cv2.threshold(gray, 230, 255, cv2.THRESH_BINARY)

src = np.array(th, dtype="float32")

cv2.imwrite("images/CIMG2478.JPG", src)

if len(src.shape) == 3:
height, width, channels = src.shape[:3]
else:
height, width = src.shape[:2]

channels = 1

print("dtype(src) " + str(src.dtype))


image, contours, hierarchy = cv2.findContours(
th, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

cnt = contours[0]

print("dtype(cnt): " + str(cnt.dtype))

cnt_ = np.array(cnt, dtype="float32")

print("dtype(cnt_): " + str(cnt_.dtype))

(x, y), radius = cv2.minEnclosingCircle(cnt)
center = (int(x), int(y))
radius = int(radius)


img = cv2.circle(img, center, 200, (0, 0, 255), 2)

cv2.imwrite("images/CIMG4555_1.JPG", img)

print(center)
print(radius)


print("OK")
7 changes: 7 additions & 0 deletions canny.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import cv2

img = cv2.imread("images/point.JPG")
gray = cv2.cvtColor(img, cv2.COLOR_RGBA2GRAY)
dst = cv2.Canny(gray, 350, 600)

cv2.imwrite("images/point.JPG", dst)
64 changes: 64 additions & 0 deletions ellispe_fitting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import cv2
import numpy as np

# 画像の読み込み
img = cv2.imread("images/volto_copy.png")


# 塗りつぶし
height, width, channels = img.shape[:3]

print("width: " + str(width))
print("height: " + str(height))

cv2.rectangle(img, (1, height), (width, 1), (0, 0, 0),
thickness=30, lineType=cv2.LINE_4)

cv2.imwrite("images/CIMG4192.JPG", img)


# ガウスのぼかし処理
gau = cv2.GaussianBlur(img, (5, 5), 0)

# グレースケール化
gray = cv2.cvtColor(gau, cv2.COLOR_BGR2GRAY)

# 2値化
ret, th = cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU)
cv2.imwrite("images/volto_out2.png", th)

#
src = np.array(th, dtype="float32")


if len(src.shape) == 3:
height, width, channels = src.shape[:3]
else:
height, width = src.shape[:2]

channels = 1

print("dtype(src) " + str(src.dtype))

# 輪郭抽出
image, contours, hierarchy = cv2.findContours(
th, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

cnt = contours[0]

print("dtype(cnt): " + str(cnt.dtype))

cnt_ = np.array(cnt, dtype="float32")

print("dtype(cnt_): " + str(cnt_.dtype))

# 楕円フィッティング
ellipse = cv2.fitEllipse(cnt)
img = cv2.ellipse(img, ellipse, (0, 255, 0), 2)

# 焦点
print(ellipse)

cv2.imwrite("images/volto_out1.png", img)

print("OK")
13 changes: 7 additions & 6 deletions 輪郭検出1.py → extract_contour1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import numpy as np
from matplotlib.patches import Polygon

img = cv2.imread("C:\\Users\\tuzuk\\Desktop\\point.JPG")
img = cv2.imread("images/point.JPG")

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

ret,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
ret, thresh1 = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)

contours = cv2.findContours(gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

contours = cv2.findContours(gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)


def draw_contours(ax, img, contours):
ax.imshow(img)
ax.axis('off')
Expand All @@ -21,7 +21,8 @@ def draw_contours(ax, img, contours):
ax.add_patch(Polygon(cnt, color='b', fill=None, lw=2))
# 輪郭の点を描画する。
ax.plot(cnt[:, 0], cnt[:, 1], 'ro', mew=0, ms=4)



fig, ax = plt.subplots(figsize=(6, 6))
draw_contours(ax, img, contours)
plt.show()
plt.show()
12 changes: 12 additions & 0 deletions extract_contour2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import cv2

img = cv2.imread("images/point.JPG")

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

contours = cv2.findContours(gray, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

cnt = contours[0]
result = cv2.drawContours(img, [cnt], 0, (0, 255, 0), 3)

cv2.imwrite("images/point_canny.JPG", result)
63 changes: 63 additions & 0 deletions line_fitting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import cv2
import numpy as np

img = cv2.imread("images/hand_gau_out1.JPG")

# 塗りつぶし
height, width, channels = img.shape[:3]

print("width: " + str(width))
print("height: " + str(height))

cv2.rectangle(img, (1, height), (width, 1), (0, 0, 0),
thickness=100, lineType=cv2.LINE_4)

cv2.imwrite("images/hand_gau_draw.JPG", img)


# ガウスのぼかし処理
gau = cv2.GaussianBlur(img, (99, 99), 0)

# グレースケール化
gray = cv2.cvtColor(gau, cv2.COLOR_BGR2GRAY)

# 2値化
ret, th = cv2.threshold(gray, 50, 255, cv2.THRESH_BINARY)
cv2.imwrite("images/hand_gau_out2.JPG", th)

src = np.array(th, dtype="float32")

# cv2.imwrite("images/CIMG2478.JPG", src)

if len(src.shape) == 3:
height, width, channels = src.shape[:3]
else:
height, width = src.shape[:2]

channels = 1

print("dtype(src) " + str(src.dtype))


image, contours, hierarchy = cv2.findContours(
th, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

cnt = contours[0]

print("dtype(cnt): " + str(cnt.dtype))

cnt_ = np.array(cnt, dtype="float32")

print("dtype(cnt_): " + str(cnt_.dtype))

rows, cols = img.shape[:2]
[vx, vy, x, y] = cv2.fitLine(cnt, cv2.DIST_L2, 0, 0.01, 0.01)
lefty = int((-x*vy/vx) + y)
righty = int(((cols-x)*vy/vx)+y)
img = cv2.line(img, (cols-1, righty), (0, lefty), (0, 255, 0), 2)


print(lefty)
print(righty)

cv2.imwrite("images/hand_gau_out1.JPG", img)
62 changes: 0 additions & 62 deletions 楕円フィッティング.py

This file was deleted.

61 changes: 0 additions & 61 deletions 直線フィッティング.py

This file was deleted.

15 changes: 0 additions & 15 deletions 輪郭検出2.py

This file was deleted.

Loading