python机器识别追踪_Python+OpenCV实现实时眼动追踪的示例代码

本文介绍了一个使用Python和OpenCV实现的实时眼动追踪项目,仅需普通摄像头即可实现。通过加载预训练的分类器检测面部和眼睛,并使用SimpleBlobDetector处理眼珠。项目包括主程序和人眼检测程序,可以显示并追踪左右眼的眼球位置。
摘要由CSDN通过智能技术生成

使用Python+OpenCV实现实时眼动追踪,不需要高端硬件简单摄像头即可实现,效果图如下所示。

项目主程序如下:

import sys

import cv2

import numpy as np

import process

from PyQt5.QtCore import QTimer

from PyQt5.QtWidgets import QApplication, QMainWindow

from PyQt5.uic import loadUi

from PyQt5.QtGui import QPixmap, QImage

class Window(QMainWindow):

def __init__(self):

super(Window, self).__init__()

loadUi('GUImain.ui', self)

with open("style.css", "r") as css:

self.setStyleSheet(css.read())

self.face_decector, self.eye_detector, self.detector = process.init_cv()

self.startButton.clicked.connect(self.start_webcam)

self.stopButton.clicked.connect(self.stop_webcam)

self.camera_is_running = False

self.previous_right_keypoints = None

self.previous_left_keypoints = None

self.previous_right_blob_area = None

self.previous_left_blob_area = None

def start_webcam(self):

if not self.camera_is_running:

self.capture = cv2.VideoCapture(cv2.CAP_DSHOW) # VideoCapture(0) sometimes drops error #-1072875772

if self.capture is None:

self.capture = cv2.VideoCapture(0)

self.camera_is_running = True

self.timer = QTimer(self)

self.timer.timeout.connect(self.update_frame)

self.timer.start(2)

def stop_webcam(self):

if self.camera_is_running:

self.capture.release()

self.timer.stop()

self.camera_is_running = not self.camera_is_running

def update_frame(self): # logic of the main loop

_, base_image = self.capture.read()

self.display_image(base_image)

processed_image = cv2.cvtColor(base_image, cv2.COLOR_RGB2GRAY)

face_frame, face_frame_gray, left_eye_estimated_position, right_eye_estimated_pos

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值