Browse Source

改善处理速度不够....

master
老赵 8 months ago
parent
commit
d7f072affa
1 changed files with 13 additions and 9 deletions
  1. 13
    9
      test/camera.py

+ 13
- 9
test/camera.py View File

@@ -24,8 +24,8 @@ class TestCamera(unittest.TestCase):
self.assertTrue(True)

def basic_process(self):
import time
import cv2
import numpy as np
from iseeu import Camera
camera = Camera(camera=0, frame_width=640, frame_height=480, framerate=30)
fgbg = cv2.createBackgroundSubtractorMOG2(history=0,
@@ -42,7 +42,12 @@ class TestCamera(unittest.TestCase):
break
data = camera.read()
if data is not None:
frame, *_ = data
frame, _, frame_time = data

# 处理速度不够 :(
if time.time() - frame_time > 0.01:
continue

cv2.imshow('frame', frame)

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
@@ -53,16 +58,15 @@ class TestCamera(unittest.TestCase):

fgmask = fgbg.apply(frame)
cv2.imshow('fgmask', fgmask)

found_faces = face_cascade.detectMultiScale(gray, 1.3, 5)
faces = frame.copy()
for (x, y, w, h) in found_faces:
faces = cv2.rectangle(faces, (x, y), (x+w, y+h), (255, 0, 0), 2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = faces[y:y+h, x:x+w]
eyes = eye_cascade.detectMultiScale(roi_gray)
for (ex, ey, ew, eh) in eyes:
cv2.rectangle(roi_color, (ex, ey), (ex+ew, ey+eh), (0, 255, 0), 2)
faces = cv2.rectangle(faces, (x, y), (x+w, y+h), (0, 255, 0), 3)
# roi_gray = gray[y:y+h, x:x+w]
# roi_color = faces[y:y+h, x:x+w]
# eyes = eye_cascade.detectMultiScale(roi_gray)
# for (ex, ey, ew, eh) in eyes:
# cv2.rectangle(roi_color, (ex, ey), (ex+ew, ey+eh), (0, 255, 0), 2)
cv2.imshow('faces', faces)

self.assertTrue(True)

Loading…
Cancel
Save