Skip to content
Snippets Groups Projects
Commit 04e99fa7 authored by zalonzo2's avatar zalonzo2
Browse files

Final changes on 4/3. First test images using camera of mini board and first...

Final changes on 4/3. First test images using camera of mini board and first images of chess pieces. Take more tests tomorrow
parent db23e0fc
No related branches found
No related tags found
No related merge requests found
......@@ -104,12 +104,6 @@ def filter_lines(lines, min_distance):
def find_board(img):
vertical_lines, horizontal_lines = find_longest_lines(img)
if (len(vertical_lines) != 9 or len(horizontal_lines) != 9):
print("Error: Grid does not match expected 9x9")
print("# of Vertical:",len(vertical_lines))
print("# of Horizontal:",len(horizontal_lines))
return None, None
# create bitmasks for vert and horiz so we can get lines and intersections
height, width, _ = img.shape
vertical_mask = np.zeros((height, width), dtype=np.uint8)
......@@ -156,6 +150,12 @@ def find_board(img):
# cv2.destroyAllWindows()
display_img([board_lines_img])
if (len(vertical_lines) != 9 or len(horizontal_lines) != 9):
print("Error: Grid does not match expected 9x9")
print("# of Vertical:",len(vertical_lines))
print("# of Horizontal:",len(horizontal_lines))
return None, None
# find largest contour and get rid of it because it contains weird edges from lines
max_area = 100000 # we're assuming board is going to be big (hopefully to speed up computation on raspberry pi)
largest = -1
......
cam_test_images/piecetest1-cropped.jpg

31.3 KiB

cam_test_images/piecetest1.jpg

476 KiB

cam_test_images/test1.png

1.37 MiB

cam_test_images/test2.png

1.37 MiB

cam_test_images/test3.png

6.6 MiB

cam_test_images/test4-cropped.png

342 KiB

cam_test_images/test4-orig.png

3.67 MiB

......@@ -32,7 +32,7 @@ class ChessGame:
init_show_cv(self.show_cv)
preview_config = self.picam2.create_preview_configuration(main={"size": (512, 512)})
preview_config = self.picam2.create_preview_configuration(main={"size": (2000, 2000)})
self.picam2.configure(preview_config)
if (self.show_cam):
self.picam2.start_preview(Preview.QTGL)
......@@ -50,14 +50,15 @@ class ChessGame:
# orig_img = cv2.imread('test_images/board1.jpg') # TODO - CHANGE TO MAKE IT RECEIVE INPUT FROM CAMERA
orig_img = self.take_pic()
h,w,c = orig_img.shape
cropped_img = orig_img[0:h, int(w/2 - h/2 - 60):int(w/2 + h/2 + 100)]
cropped_img = orig_img[0:h-100, 0:w-100]
img = cv2.resize(cropped_img, (512, 512))
# img = orig_img
if (self.show_cv):
# cv2.imshow('Original Image Before Processing', img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
display_img([img])
display_img([orig_img, img])
warped_img, sorted_warped_points = find_board(img)
......@@ -96,7 +97,7 @@ class ChessGame:
self.img_idx += 1
time.sleep(2)
img_txt = 'board' + str(self.img_idx) + '.jpg'
print(img_txt)
# print(img_txt)
img_path = os.path.join('game_images', img_txt)
metadata = self.picam2.capture_file(img_path)
return cv2.imread(img_path)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment