Пример #1
0
    def draw(self):
        '''Draws main GUI, then loops on frames'''
        grid = QGridLayout()
        
        self.leftbox = ImageBox()
        grid.addWidget(self.leftbox,0,0)

        self.rightbox = ControlBox(self)
        grid.addWidget(self.rightbox, 0, 1)
        
        variables = (0.25, 10, 5, 100, (0.5,0,0.5), False, (200.0,0.34,0.25), 2)
        #create Video object
        vid = Video(0,variables)
        
        while(True):
            
            # Read every frame and extract images
            vid.readFrame()
            frame_as_string_before = vid.getCurrentFrame().tostring()
            vid.findFaces()
            self.face_list = vid.getFaces()
            
            # If we've clicked the num button, draw rectangles around each face
            if self.draw_nums:
                for i in range(len(self.face_list)):
                    # Uncomment if we don't want to use predicted position
#                    vid.showRectangle(self.face_list[i].getPosition(),self.face_list[i].getID())
                    # If the face is obscured, draw the rectangle around the predicted position
                    if not face.isObscured():
                        vid.showRectangle(self.face_list[i].getPosition(),self.face_list[i].getID())
                    else:
                        vid.showRectangle(self.face_list[i].getPredictedPosition(),self.face_list[i].getID())
     
                
            frame = vid.getCurrentFrame()
            
            rects = []
        
            #Get position of each face
            for face in self.face_list:
                # Position of each face (for use in Control Box) based on last detected position, not predicted
                tuples = face.getPosition()
                rects.append([tuples[0][0], tuples[0][1], tuples[1][0], tuples[1][1]])
                # Uncomment if we want to base it on predicted
#                if not face.isObscured():
#                    tuples = face.getPosition()
#                    rects.append([tuples[0][0], tuples[0][1], tuples[1][0], tuples[1][1]])
#                else:
#                    tuples = face.getPredictedPosition()
#                    if tuples:
#                        rects.append([tuples[0][0], tuples[0][1], tuples[1][0], tuples[1][1]])
               
                
            # Transform cv2 frame (numpy array) into QPixmap via string and QImage
            cv2.cvtColor(frame, cv.CV_BGR2RGB, frame)
            frame_as_string = frame.tostring()
            
            image = QImage(frame_as_string,\
            frame.shape[1],frame.shape[0],QImage.Format_RGB888)
            pixmap = QPixmap.fromImage(image) 
            
            # Get images of faces for use in Control Box
            face_pics = get_imgs_from_rects(image, rects)
           
            # DON'T DELETE
            # What does it do
            # WHO KNOWS
            if cv2.waitKey(1) & 0xFF == ord('q'):
                vid.endWindow()
                break
            
            # Update everything with current face info
            self.leftbox.set_image(pixmap, self.face_list, face_pics)
            self.rightbox.setFaces(face_pics, self.face_list)
            
            self.setLayout(grid)
            self.show()