Home > other >  [for] Python OpenCV library imshow function in multiple Windows
[for] Python OpenCV library imshow function in multiple Windows

Time:11-23

System environment: Ubuntu

Language: Python

Intended purpose: using face_recognition library and OpenCV library computer camera real-time face recognition

Problems: real-time face detection functions such as there is no problem, but every time I open the program will be open in addition to the camera images of multiple gray small window, that is to say every time open the program, in addition to real-time camera detection images will also have more than one gray, together without any display window is opened,

Source:
1 the import cv2
2 the import face_recognition
3 the import numpy as np
4 the import knn_clf as kc
5
6
7 # define functions provides
8 def train_classify_model (face_data_path classifier_name) :
9 the try:
10 classify_file=open (classifier_name)
11 classify_file. Close ()
12 the except FileNotFoundError:
13 print (" Training the classify model, both please stand by. \ n ")
14 the print ("... \ n ")
15 classify_file=kc. "train" (face_data_path classifier_name)
16 print ("... \ n ")
17 print (" Trainning Process sucessfully completed. \ n ")
18
19
20 # "train" the classify model
21 classify_model_name='a.t xt'
22 classify_model="../train_model/" + classify_model_name
23 known_face_path="../face_data_base known_face
"24 train_classify_model (known_face_path, classify_model)
25
26
27 # initiate camera
28 v_c=cv2. VideoCapture (0)
29 # rval, frame=v_c. Read ()
30 while True:
31 rval, frame=v_c. Read ()
32 # convert color to RGB
33 resized_frame=cv2. Resize (frame, None, fx=0.25, fy=0.25)
34 rgb_resized_frame=cv2. CvtColor (resized_frame, cv2 COLOR_BGR2RGB)
35 # compare faces
36 classify_results=kc predict (rgb_resized_frame, None, classify_model, 0.4)
37 if classify_results!=[] :
38 # the draw a rectangle and the name on the faces
39 for classify_result classify_results in:
40 # if classify_result [0]=="unknown" :
41 top, right, bottom, left=classify_result [1]
42 top *=4
43 right *=4
44 bottom *=4
45 left *=4
46 cv2. A rectangle (frame, (left, top), (right, bottom), (145158, 0), (2)
47 cv2. A rectangle (frame, (left, bottom - 35) and (right, bottom), (255255255), 1)
48 cv2. PutText (frame, classify_result [0], (left + 6, bottom - 6), cv2. FONT_HERSHEY_SIMPLEX, 1, (0, 0), (1)
49 cv2. Imshow (" Classifier, "frame)
50 if cv2. WaitKey (1) & amp; 0 XFF==word (' q ') :
51 break
52
53 v_c. Release ()
54 cv2. DestroyAllWindows ()

Problem screenshots:
  • Related