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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| import threading
import cv2 #For computer vision
import numpy as np # provides a high-performance multidimensional array
import calendar
import time
import pygame
import serial
#########################################################fonction de parsing du gps
def extract_coordinates(gprmc_sentence):
# Séparation de la trame en ses parties en utilisant la virgule comme séparateur
parts = gprmc_sentence.split(',')
# Vérification si la trame est valide et si elle contient des données de position
if len(parts) < 10 or parts[2] != 'A':
return None, None
# Extraction de la latitude
latitude = float(parts[3][:2]) + float(parts[3][2:]) / 60
if parts[4] == 'S':
latitude *= -1
# Extraction de la longitude
longitude = float(parts[5][:3]) + float(parts[5][3:]) / 60
if parts[6] == 'W':
longitude *= -1
return latitude, longitude
##################################################fin de fonction parsing du gps
class MyThread (threading.Thread):
def __init__ (self):
threading.Thread.__init__ (self, target=self.run)
def run (self):
for T in range(1000):
print("T a pour valeur", T)
time.sleep(1)
#----------------------------------------------------------------------------------------------------------
# Creating Haarcascade Variable
nplateCascade = cv2.CascadeClassifier("haarcascades\haarcascade_russian_plate_number.xml")
# ---------------------------------------------------------------------------------------------------------
# Initializing Variable
minarea = 600
count = 0
framewidth = 640
frameheight = 480
#framewidth = 1280
#frameheight = 720
# Number Plate Capturing
web_cap = cv2.VideoCapture(0)
web_cap.set(3,framewidth)
web_cap.set(4,frameheight)
web_cap.set(10,100) # Brightness id = 10 and 100 intensity level
pygame.mixer.init()
while True :
success, img = web_cap.read()
# rotate the image by 90 degree clockwise
#img = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE)
img = cv2.rotate(img, cv2.ROTATE_180)
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
numberplates = nplateCascade.detectMultiScale(imgGray, 1.1, 4) # 4 : minimum neighbour
# Create bounding box
for (x, y, w, h) in numberplates:
area = w * h
if area > minarea:
# sauvegarde image voiture
current_GMT = time.gmtime()
secondes = current_GMT.tm_sec # pour requete gps usb
timestamp = calendar.timegm(current_GMT)
cv2.imwrite("voiture/voiture_" + str(timestamp) + "_" + gps_position + ".jpg", img)
# dessine un rectangle et ecrit
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0),
2) # (x,y) : Initial points & (x+w,y+h) : Diagonal points
cv2.putText(img, "Number plate", (x, y - 5), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 0, 0), 2)
imgRoi = img[y:y + h, x:x + w] # Region of number plate
cv2.imshow("ROI IMAGE", imgRoi)
# sauvegarde la plaque uniquement
cv2.imwrite("plaque/plaque_" + str(timestamp) + "_" + gps_position + ".jpg", imgRoi)
print("++++++++" + gps_position)
pygame.mixer.music.load("mp3/alarme.mp3")
pygame.mixer.music.play()
cv2.imshow("Video", img)
Thread1 = MyThread ()
Thread1.start() |
Partager