python - 进程中发送的函数不能改变类字段的值
问题描述
变量 self.process_this_frame 在过程中没有改变。现在我只想在处理应该处理的前一帧并跳过其他帧时处理帧。
import cv2
import face_recognition
import multiprocessing
class FaceLocationSender:
def __init__(self, camera_url):
self.video_capture = cv2.VideoCapture(camera_url)
self.face_locations = []
self.process_this_frame = True
def get_faces_from_frame(self, frame):
self.face_locations = face_recognition.face_locations(frame)
self.process_this_frame = True
def start(self):
while True:
ret, frame = self.video_capture.read()
small_frame = cv2.resize(frame, (0, 0), fx=1/2, fy=1/2)
rgb_small_frame = small_frame[:, :, ::-1]
if self.process_this_frame:
self.process_this_frame = False
process = multiprocessing.Process(target=self.get_faces_from_frame, args=(rgb_small_frame,))
process.start()
for (top, right, bottom, left) in self.face_locations:
top *= 2
right *= 2
bottom *= 2
left *= 2
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 0), 2)
cv2.imshow('Video', cv2.resize(frame, (1200, 600)))
if cv2.waitKey(1) & 0xFF == ord('q'):
break
self.video_capture.release()
cv2.destroyAllWindows()
解决方案
推荐阅读
- c++ - TCP连接的奇怪行为
- python - OR-tools 路由优化节点兼容性
- php - Laravel:在某些浏览器中下载的文件缺少扩展名
- javascript - Vue js - 转到页面时注册组件时出错
- node.js - 错误:在 adminbro 教程中找不到模块“tslib”
- kotlin - Setter 没有在 Kotlin 中赋值
- reactjs - 为什么每当我在 Reactjs 中重新加载我的仪表板组件时,我的登录组件会闪烁?
- php - 设置 WooCommerce 计费公司时禁用特定付款方式
- python - 如何更正此错误:OverflowError: cannot convert float infinity to integer
- c# - 在 C# 方法中将 PowerShell 参数从字典更改为字符串列表