-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
79 lines (60 loc) · 2.42 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# import pydevd_pycharm
# pydevd_pycharm.settrace('localhost', port=5678, stdoutToServer=True, stderrToServer=True)
from QR_codes.QR_Read import *
from rps_logic import *
import logging
import franka_python
import cv2
def main():
cam = WebcamStream(display=True, src=0)
cam.run()
contoller = franka_python.RobotControl()
while True:
while True:
image = cam.frame_queue.get()
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
decoded, detected = read_qr_code(image)
# print(decoded)
sorted_qr_codes = sort_codes(decoded, detected, qr_strings)
if len(sorted_qr_codes['grid_corners']) == 4 :
break
try:
plane_edges = centres_of_qr([item[1] for item in sorted_qr_codes['grid_corners']])
except:
continue
transform_matrix, transform_image = perspective_transform(plane_edges, image)
cv2.imwrite("_transformed.png", cv2.cvtColor(transform_image, cv2.COLOR_RGB2BGR))
cv2.imwrite("_original.png", cv2.cvtColor(image, cv2.COLOR_RGB2BGR))
if len(sorted_qr_codes['rps_blocks']) >= 0 :
blocks = [Blocks(item[0], item[1], transform_matrix) for item in sorted_qr_codes['rps_blocks']]
for block in blocks:
print(block.block_name)
print(block.mapped_centre)
else:
blocks = None
if len(sorted_qr_codes['rps_cards']) >= 0:
cards = [Cards(item[0], item[1], transform_matrix) for item in sorted_qr_codes['rps_cards']]
for card in cards:
print(card.card_name)
print(card.mapped_centre)
else:
cards = None
print("no card played")
if len(cards) == 1:
card = cards[0]
to_play = match_card(card.card_name)
# block = None
if blocks != None:
for b in blocks:
if b.block_name == to_play:
block = b
block_cord = [int(x) for x in block.mapped_centre.flatten()]
print(block_cord)
y, x = block_cord # inverted x and y to match cord systems
contoller.pick_place(x, y)
input("press enter to play again")
print("complete")
else:
print("no or wrong number of cards played")
if __name__ == "__main__":
main()