Ai
4 Star 1 Fork 0

wjwilliam/software_engineering-dlib_face_recognition

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Capture.py 2.25 KB
一键复制 编辑 原始数据 按行查看 历史
royalwjw 提交于 2022-06-18 00:54 +08:00 . init&重构项目
import cv2
from PyQt5.QtCore import QThread,pyqtSignal
import numpy as np
from PyQt5.QtGui import QImage
from src.utils.GlobalVariable import models
#from PIL import Image, ImageDraw, ImageFont
# 子线程 take photo 并发出信号
class Capture(QThread):
emit_img = pyqtSignal(list,QImage)
def __init__(self):
super().__init__()
self.frame = np.random.randint(255, size=(900, 800, 3),#颜色为0-255的随机数,size为图片大小,3为RGB, dtype=np.uint8数据类型,8个bit
dtype=np.uint8) #待识别帧初始化
self.cap = None
def run(self):
while True:
ret, frame = self.cap.read()
if ret:
p = convertToQtFormat(frame)
self.emit_img.emit([frame],p)
def close(self): #关闭线程
if self.isRunning():
self.terminate()
self.wait()
if self.cap is not None:
self.cap.release()
cv2.destroyAllWindows()
#转换位qt图像格式
def convertToQtFormat(frame_show):
rgbImage = cv2.cvtColor(frame_show, cv2.COLOR_BGR2RGB)
gray = cv2.cvtColor(rgbImage,cv2.COLOR_RGB2GRAY)
faces = models.detector(gray)
if len(faces) == 1:
face = faces[0]
cv2.rectangle(rgbImage, (face.left(), face.top()), (face.right(), face.bottom()), (255,0,0), 4)
h, w, ch = rgbImage.shape
bytesPerLine = ch * w
convertToQtFormat = QImage(rgbImage.data, w, h, bytesPerLine,
QImage.Format.Format_RGB888)
p = convertToQtFormat.scaled(460, 530)
return p
#为图片渲染中文
# def put_chines_test(frame, chinnes_text):
# rgbImage = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# location = models.detector(rgbImage)
# if len(location) == 1:
# location = location[0]
# font = ImageFont.truetype("./resources/simsun.ttc",
# 50,
# encoding="utf-8")
# rgbImage = Image.fromarray(rgbImage)
# draw = ImageDraw.Draw(rgbImage)
# draw.text(((location.right() + 6, location.top() - 6)), chinnes_text,
# (0, 0, 255), font)
# rgbImage = np.asarray(rgbImage)
# return rgbImage
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wjwilliam/software_engineering-dlib_face_recognition.git
git@gitee.com:wjwilliam/software_engineering-dlib_face_recognition.git
wjwilliam
software_engineering-dlib_face_recognition
software_engineering-dlib_face_recognition
master

搜索帮助