Created
November 17, 2022 08:10
-
-
Save JoshuaJakowlew/509d331779719f3b6cf5f8900f948f79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
import cv2 | |
def show_graph(x_list, y_list, width, height): | |
plt.figure(figsize = [width, height]) | |
plt.scatter(x_list, y_list, marker='.', s=5) | |
plt.show() | |
return | |
image = cv2.imread('test/b1_00.png') | |
gray = cv2.inRange(image, np.array([0, 0, 0]), np.array([50, 50, 50])) | |
cv2.imshow('mask', gray) | |
cv2.waitKey(0) | |
# gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
# Find Canny ed | |
# edged = cv2.Canny(gray, 30, 200) | |
# cv2.imshow('edged', edged) | |
edged = gray | |
contours, hierarchy = cv2.findContours(edged, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) | |
for c in contours: | |
epsilon = 0.005 * cv2.arcLength(c, True) | |
approximations = cv2.approxPolyDP(c, epsilon, True) | |
cv2.drawContours(image, [approximations], 0, (0), 3) | |
print(approximations) | |
# cv2.drawContours(image, contours, -1, (0, 255, 0), 3) | |
cv2.imshow('Canny Edges After Contouring', image) | |
cv2.waitKey(0) | |
dims = image.shape | |
x_list, y_list = [], [] | |
for x in np.arange(0, dims[1], 1): | |
for y in np.arange(0, dims[0], 1): | |
if np.all(image[y][x] == (0, 0, 0)): | |
x_list.append(x) | |
y_list.append(750-y) | |
show_graph(x_list, y_list, 18, 3) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment