コード例 #1
0
    def show_frame(self):
        #Read the input feed, flip it, resize it and show it in the corresponding label
        ret, frame = cap.read()
        flipFrame = cv2.flip(frame, 1)
        cv2image = cv2.resize(flipFrame, (vidWidth, vidHeight));
        img1 = Image.fromarray(cv2image)
        imgtk1 = ImageTk.PhotoImage(image=img1)
        videoStream1.imgtk1 = imgtk1
        videoStream1.configure(image=imgtk1)
        
        #Call the threholding function
        threshPupil, threshGlint = imgThreshold.imgThreshold(frame)
        
        #Call Edge Detection of binary frame
        cpX,cpY,cp,ccX,ccY,cc,successfullyDetected = edgeDet.edgeDetectionAlgorithm(threshPupil,threshGlint)
        #Draw around the pupil and glint
        print('cpX: ', cpX, ' cpY: ', cpY, ' ccX: ', ccX, ' ccY: ', ccY)
        #print successfullyDetected
        if cpX is None or cpY is None or ccX is None or ccY is None:
            print('pupil or corneal not detected, skipping...')
        else:
            # Ellipse Fitting
            frameCopy = frame.copy()
            
            #draw pupil centre
            cv2.circle(frameCopy, (cpX,cpY),3,(0,255,0),-1)
            
            #draw pupil circumference
            cv2.drawContours(frameCopy,cp,-1,(0,0,255),3)
            
            #draw corneal centre
            cv2.circle(frameCopy, (ccX,ccY),3,(0,255,0),-1)
            
            #draw corneal circumference
            cv2.drawContours(frameCopy,cc,-1,(0,0,255),3)
           
            #Show detected pupil
            if(frameCopy != None):
                frameC_resized = cv2.resize(frameCopy, (vidWidth, vidHeight), interpolation = cv2.INTER_AREA)
                frameC_resized = cv2.flip(frameC_resized, 1)
                img1 = Image.fromarray(frameC_resized)
                imgtk1 = ImageTk.PhotoImage(image=img1)
                videoStream1.imgtk1 = imgtk1
                videoStream1.configure(image=imgtk1)
            
            #If mouseToggle is true implement the cursor control code
            #Allows user to interact with computer wiht their eyes
            if mouseToggle:
                if 'aOriginal' in globals() and 'bOriginal' in globals():
                    # Centre points of glint and pupil pass to vector
                    gazeX, gazeY = GGP.getGazePoint(aOriginal, bOriginal, cpX, cpY, ccX, ccY)
                    ATE.move_mouse(gazeX, gazeY)
                    infoLabel.configure(text = "Now tracking your eye!")
                else:
                    infoLabel.configure(text = "You have not calibrated yet, please do so")

        videoStream1.after(5, self.show_frame)
コード例 #2
0
        cv2.circle(frameCopy, (cpX,cpY),3,(0,255,0),-1)
        
        #draw pupil circumference
        cv2.drawContours(frameCopy,cp,-1,(0,0,255),3)
    
        #draw corneal centre
        cv2.circle(frameCopy, (ccX,ccY),3,(0,255,0),-1)
    
        #draw corneal circumference
        cv2.drawContours(frameCopy,cc,-1,(0,0,255),3)
    

        cv2.imshow('frame detected', frameCopy)

        print('cpX: ', cpX, ' cpY: ', cpY, ' ccX: ', ccX, ' ccY: ', ccY)
        # Centre points of glint and pupil pass to vector
#        print('Gaze points X and Y:')
        x, y = GGP.getGazePoint(aOriginal, bOriginal, cpX, cpY, ccX, ccY)
    
#ATE.move_mouse(x,y)
	
        # Show frames
        #cv2.imshow('frame',frame_gray)
#        cv2.imshow('binary',frameBinary)
        #cv2.imshow('binary inv', frameBinaryInv)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
#target.close()
cv2.destroyAllWindows()
コード例 #3
0
        #draw pupil circumference
        cv2.drawContours(frameCopy,cp,-1,(0,0,255),3)
    
        #draw corneal centre
        cv2.circle(frameCopy, (ccX,ccY),3,(0,255,0),-1)
    
        #draw corneal circumference
        cv2.drawContours(frameCopy,cc,-1,(0,0,255),3)
    

        cv2.imshow('frame detected', frameCopy)

        print('cpX: ', cpX, ' cpY: ', cpY, ' ccX: ', ccX, ' ccY: ', ccY)
        # Centre points of glint and pupil pass to vector
#        print('Gaze points X and Y:')
        gazeX, gazeY = GGP.getGazePoint(aOriginal, bOriginal, cpX, cpY, ccX, ccY)
        if callback.click_count == 0:
            target.write("%d %d %d\n" % (gazeX, gazeY, -1))

        if callback.click_count != click_count_prev:
            target.write("%d %d %d\n" % (gazeX, gazeY, callback.click_count))
            click_count_prev = callback.click_count
        else:
            target.write("%d %d %d\n" % (gazeX, gazeY, -1))
    
        #ATE.move_mouse(x,y)
	
        # Show frames
        #cv2.imshow('frame',frame_gray)
#        cv2.imshow('binary',frameBinary)
        #cv2.imshow('binary inv', frameBinaryInv)