Pedestrian Crossing Radar Management System
FileName – fayl nomi filter -
Download 3.29 Mb.
|
Pedestrian Crossing Radar Management System full - для слияния
- Bu sahifa navigatsiya:
- “Pedestrian Crossing Radar Management System”
FileName – fayl nomi
filter - tozalagich, filtr, filterlamoq, tozalamoq find – topmoq font – shrift index - 1) ko`rsatkich, alfavit korsatkichi; 2) katalog, ro`yxat; indeks; 3) strelka (ko`rsatkich), length - 1) uzunlik, masofa; 2) ketgan vaqt, davom etish muddati modified - biror narsaning o`zgargan shakli, turlanish no – yo`q pate – qo`yish share - (with, among, between) vt 1) taqsimlamoq, bo`l(ish)moq; 2) paylashmoq ShowMessage – habarni ko`rsatmoq simple - oson, oddiy, soda size – hajm, kattalik, o`lchov switch - birdan fikrini o`zgartirmoq text – matn type - ~ of n [c] 1) tur; 2) bosma harf; 3) tip, xil, nusxa visible - 1) ko`zga ko`rinadigan, ko`z ilg`aydigan; 2) aniq, oshkora yes – ha true – rost false – yolg‘on Glossary
Python dasturida “Pedestrian Crossing Radar Management System” dasturini yaratish Asosiy Formaga: Label Timer Panel PictureBox Button komponentalarini tashlaymiz. “Pedestrian Crossing Radar Management System” dasturining kodlari. Umumiy kod: MainForms.py faylining kodlari: import cv2 as cv import numpy as np import imutils import time import datetime import os t = time.strftime("%Y-%m-%d_%H-%M-%S") #timeFolder = time.strftime("%Y-%m-%d") dateTime = str(datetime.datetime.now()) #pathFolder = os.system(f'cmd /k "mkdir" folder_{timeFolder}') img_counter = 0 # setting parameters CONFIDENCE_THRESHOLD = 0.4 NMS_THRESHOLD = 0.3 #================================================== timeFolder = time.strftime("%Y-%m-%d") def createFolder(directory): try: if not os.path.exists(directory): os.makedirs(directory) except OSError: print("Error: Creating directory. " + directory) #createFolder('./test/') createFolder(timeFolder) #================================================== #================================================== import mediapipe as mp width=640 height=480 mp_drawing = mp.solutions.drawing_utils mp_face = mp.solutions.face_detection.FaceDetection(model_selection=1,min_detection_confidence=0.5) def obj_data(img): global img_counter, pathFolder image_input = cv.cvtColor(img, cv.COLOR_BGR2RGB) results = mp_face.process(image_input) if not results.detections: print("NO FACE") else: for detection in results.detections: bbox = detection.location_data.relative_bounding_box #print(bbox) x, y, w, h = int(bbox.xmin*width), int(bbox.ymin * height), int(bbox.width*width),int(bbox.height*height) start_point = (x-100, y-100) end_point = (x+w+80, y+h+80) #cv.rectangle(img,(x-100,y-100),(x+w+80,y+h+80),(0,0,255),2) cv.rectangle(img, start_point, end_point,(0,0,255),2) #print(cv.rectangle(img,(x-100,y-100),(x+w+80,y+h+80),(0,0,255),2)) #if yuz is True: ## img_name = f"{pahtFolder}/detect_"+t+"_{img_counter}.png"#.format(pathFolder, img_counter) ## cv.imwrite(img_name, frame) ## #print("screeenshot taken") ## img_counter += 1 #================================================== COLORS = [(0,255,255), (255,255,0), (0,255,0), (255,0,0), (255,0,255), (255,0,0)] GREEN = (0,255,0) RED = (0,0,255) PINK = (147,20,255) ORANGE = (0,69,255) BLACK = (0,255,0) # defining fonts fonts = cv.FONT_HERSHEY_COMPLEX # reading class name from text file class_names = [] with open("dnn_model/classes.txt", "r") as f: class_names = [cname.strip() for cname in f.readlines()] # setting up opencv net yoloNet = cv.dnn.readNet('dnn_model/yolov4-tiny.weights', 'dnn_model/yolov4-tiny.cfg') yoloNet.setPreferableBackend(cv.dnn.DNN_BACKEND_CUDA) yoloNet.setPreferableTarget(cv.dnn.DNN_TARGET_CUDA_FP16) model = cv.dnn_DetectionModel(yoloNet) model.setInputParams(size=(416,416), scale=1/255, swapRB=True) def color_detect(): # color detection hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV) lower_red = np.array([0,50,120]) upper_red = np.array([10,255,255]) mask3 = cv.inRange(hsv, lower_red, upper_red) cnts3 = cv.findContours(mask3, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE) cnts3 = imutils.grab_contours(cnts3) for c in cnts3: area3 = cv.contourArea(c) if area3 > 5000: cv.drawContours(frame, [c], -1, (0,255,0), 3) M = cv.moments(c) cx = int(M["m10"]/M["m00"]) cy = int(M["m01"]/M["m00"]) cv.circle(frame, (cx, cy), 7, (255,255,255), -1) cv.putText(frame, "Red", (cx-20, cy-20), cv.FONT_HERSHEY_SIMPLEX, 2.5, (255,255,255), 3) # setting camera #def ObjectDetector(image): ## classes, scores, boxes = model.detect(image, CONFIDENCE_THRESHOLD, NMS_THRESHOLD) ## ## # creating empty list to add objects data ## data_list = [] #[classid[0], classid[67]] ## for (classid, score, box) in zip(classes, scores, boxes): ## img_counter = 0 ## # define color of each, object based on ito class id ## color = COLORS[int(classid) % len(COLORS)] ## foiz = (score*100) ## label = "%s : %f" % (class_names[classid], foiz) ## #lbl = 100 * label ## ## # draw rectangle on and label on object ## #if (classid == 0 and classid == 67): ## cv.rectangle(image, box, color, 2) ## cv.putText(image, label, (box[0], box[1]-14), fonts, 0.5, color, 2) ## for timeFrame in t: ## timeFrame = cv.putText(image, t, (10, 20), cv.FONT_HERSHEY_SIMPLEX, 0.6, (0,0,255), 1) ## ## if (classid == 67): ## cv.rectangle(image, box, color, 2) ## cv.putText(image, label, (box[0], box[1]-14), fonts, 0.5, color, 2) ## ## img_name = "detect_person_image/detect_"+t+"_{}.png".format(img_counter) ## cv.imwrite(img_name, image) ## #print("screeenshot taken") ## img_counter += 1 ## ## elif (classid == 9): ## cv.rectangle(image, box, color, 2) ## cv.putText(image, label, (box[0], box[1]-14), fonts, 0.5, color, 2) ## color_detect() ## ## img_name = "detect_person_image/detect_"+t+"_{}.png".format(img_counter) ## cv.imwrite(img_name, image) ## #print("screeenshot taken") ## img_counter += 1 ## # getting the data # 1: class name 2: object width in pixels, 3: position where have to draw text(distance) ## if classid == 0 and 67: #person class id ## data_list.append([class_names[classid[0]], box[2], (box[0], box[1]-2)]) ## elif classid == 9: ## data_list.append([class_names[classid[0]], box[2], (box[0], box[1]-2)]) ## # return list ## return data_list # load the cascade face_cascade = cv.CascadeClassifier('haarcascade_frontalface_default.xml') cap = cv.VideoCapture(0) while(cap.isOpened()): ret, frame = cap.read() frame = cv.putText(frame, dateTime, (10, 20), cv.FONT_HERSHEY_SIMPLEX, 0.6, (0,0,255), 1) #ObjectDetector(frame) classes, scores, boxes = model.detect(frame, CONFIDENCE_THRESHOLD, NMS_THRESHOLD) # creating empty list to add objects data data_list = [] #[classid[0], classid[67]] for (classid, score, box) in zip(classes, scores, boxes): # define color of each, object based on ito class id color = COLORS[int(classid) % len(COLORS)] ## foiz = round(score, 2)*100 ## label = "%s : %f" % (class_names[classid], foiz) label = class_names[classid] foiz = round(score, 2) # draw rectangle on and label on object #if (classid == 0 and classid == 67): cv.rectangle(frame, box, color, 2) cv.putText(frame, label + " {:.2f}".format(foiz*100)+"%", (box[0], box[1]-14), fonts, 0.5, color, 2) # convert to grayscale gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY) # Detect the faces faces = face_cascade.detectMultiScale(gray, 1.1, 4) ## def facesDetect(): ## for (x,y,w,h) in faces: ## cv.rectangle(frame, (x,y), (x+w,y+h), (255,0,0), 2) ## img_name = "detect_person_image/detect_"+t+"_{}.png".format(img_counter) ## cv.imwrite(img_name, frame) ## #print("screeenshot taken") ## img_counter += 1 print(box) #print(score) if (classid == 67): cv.rectangle(frame, box, color, 2) cv.putText(frame, label, (box[0], box[1]-14), fonts, 0.5, color, 2) cv.imshow('Person Radar | Developed by Sherzod Khoja Sulaiman Siddik', frame) key = cv.waitKey(1) if key == ord('q') or key == 27: break cap.release() cv.destroyAllWindows() Download 3.29 Mb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling