Commit 3109620e authored by Tom Pillot's avatar Tom Pillot
Browse files

Initial commit

parents
.idea/
__pycache__/
venv/
File added
import apriltag
import cv2
class Detector(apriltag.Detector):
def __init__(self):
super().__init__()
self.DECISION_MARGIN = 40
def detect(self, img, return_image=False):
dets = super().detect(img)
for det in dets:
if det.decision_margin > self.DECISION_MARGIN:
return det.tag_id
def detect_from_cam(self):
cam = cv2.VideoCapture(0)
cv2.namedWindow("Detection")
tag_id = None
while not tag_id:
ret, frame = cam.read()
if not ret:
print("failed to grab frame")
break
cv2.imshow("Detection", frame)
k = cv2.waitKey(1)
if k % 256 == 27:
# ESC pressed
print("Escape hit, closing...")
break
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
tag_id = self.detect(gray)
cam.release()
cv2.destroyAllWindows()
return tag_id
import sys
from PyQt5 import QtWidgets as qtw
from detector import Detector
tag_ids = {}
class MainWindow(qtw.QWidget):
def __init__(self, *args, **kargs):
super().__init__(*args, **kargs)
self.detector = Detector()
self.setWindowTitle("Liste des équipes")
self.list_view = qtw.QListWidget()
self.name_input = qtw.QLineEdit()
self.tag_label = qtw.QLabel("")
self.add_button = qtw.QPushButton("Ajouter")
self.edit_button = qtw.QPushButton("Modifier")
self.delete_button = qtw.QPushButton("Supprimer")
self.scan_button = qtw.QPushButton("Scanner le tag")
hlayout1 = qtw.QHBoxLayout()
hlayout1.addWidget(qtw.QLabel("Nom de l'équipe :"))
hlayout1.addWidget(self.name_input)
hlayout2 = qtw.QHBoxLayout()
hlayout2.addWidget(qtw.QLabel("Tag ID :"))
hlayout2.addWidget(self.tag_label)
hlayout3 = qtw.QHBoxLayout()
hlayout3.addLayout(hlayout2)
hlayout3.addWidget(self.scan_button)
hlayout4 = qtw.QHBoxLayout()
hlayout4.addWidget(self.add_button)
hlayout4.addWidget(self.edit_button)
hlayout4.addWidget(self.delete_button)
vlayout = qtw.QVBoxLayout()
vlayout.addWidget(self.list_view)
vlayout.addLayout(hlayout1)
vlayout.addLayout(hlayout3)
vlayout.addLayout(hlayout4)
self.setLayout(vlayout)
self.scan_button.clicked.connect(self.detect_tag)
self.add_button.clicked.connect(self.add_team)
self.edit_button.clicked.connect(self.edit_team)
self.delete_button.clicked.connect(self.delete_team)
self.show()
def detect_tag(self):
tag_id = self.detector.detect_from_cam()
if tag_id:
self.tag_label.setText(str(tag_id))
def add_team(self):
if self.tag_label.text() and self.name_input.text():
tag_id = int(self.tag_label.text())
name = self.name_input.text()
self.list_view.addItem(name)
self.tag_label.setText("")
self.name_input.setText("")
tag_ids[name] = tag_id
def edit_team(self):
selected = self.list_view.selectedItems()
if selected:
name = selected[0].text()
tag_id = tag_ids[name]
self.tag_label.setText(str(tag_id))
self.name_input.setText(name)
def delete_team(self):
selected = self.list_view.selectedItems()
for item in selected:
print(item)
self.list_view.takeItem(self.list_view.row(item))
if __name__ == '__main__':
app = qtw.QApplication(sys.argv)
w = MainWindow()
sys.exit(app.exec_())
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment