Club-Robotique/Position-Robot/extractcoord.py

52 lines
1.5 KiB
Python

import math
import matplotlib.image as mpimg
import numpy as np
import matplotlib.pyplot as plt
import cv2
import time
import os
import pygame
from PIL import Image
import random
class getpos():
def __init__(self):
self.win=pygame.display.set_mode((1600, 720))
self.background = (0,0,0)
self.Done = True
self.coords = []
self.pos = np.array([])
while self.Done :
self.img = Image.open(('board.jpg'))
image = self.img.resize((int(1600), int(720)))
size = image.size
mode = image.mode
data = image.tobytes()
self.displayed = pygame.image.fromstring(data, size, mode)
self.rect = self.displayed.get_rect()
self.win.blit(self.displayed, self.rect)
self.checkEvent()
pygame.display.flip()
def checkEvent(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.Done = False
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_presses = pygame.mouse.get_pressed()
if mouse_presses[0]:
x,y = pygame.mouse.get_pos()
if len(self.coords) < 4:
self.coords.append(np.array([x,y]))
if len(self.coords) == 4:
self.pos = np.array([x,y])
print('\n',self.coords,'\n', self.pos,'\n')
print(x,y)
extract = getpos()