Open MMavrick23 opened 6 years ago
You need to set the frame flag to Writable:true. After getting frame picamera. Example Code
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640, 480))
time.sleep(0.1)
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
# grab the raw NumPy array representing the image, then initialize the timestamp
# and occupied/unoccupied text
image = frame.array
image.setflags(write=True)
print(image.flags)
print(type(image))
# show the frame
cv2.imshow("Frame", image)
key = cv2.waitKey(1) & 0xFF
# clear the stream in preparation for the next frame
`rawCapture.truncate(0)`
# if the q key was pressed, break from the loop
if key == ord("q"):
break
cv2.destroyAllWindows()
it would work fine then.
Description
I'm trying to do face detection and recognition through the raspberry pi camera which is somehow not easy as openCV doesn't support this without special driver, however the driver slows down the FPS while I need full FPS for my project.
I used a custom module ( Videostream.zip ) to do this instead and also with higher FPS using threading (ex. cap = PiVideoStream().start()) ans this works fine with cv2, however when trying to use face recognition module it take a lot of processing to detect faces so instead I detect faces using haar cascades then pass it to face recognition to identify faces and this works just fine on imported images except when I try to use the camera instead, it gives an exception (expected writable numpy.ndarray with shape set).
What should I do ? What is the problem ?
What I Did
That's my code :-
from Videostream import PiVideoStream import face_recognition import numpy as np import time import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') cap = PiVideoStream().start() time.sleep(2.0)
image = face_recognition.load_image_file("mavImg.jpg") image_encoding = face_recognition.face_encodings(image)[0]
known_face_encodings = [image_encoding] known_face_names = ["Mavrick"]
while 1: Frame = cap.read() FrameRGB = Frame[:, :, ::-1] FrameGRY = cv2.cvtColor(Frame, cv2.COLOR_BGR2GRAY)