I'm trying to detect faces in an image received from a unix socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect('/path/to/socket')
data = False
while True:
buf = sock.recv(4096)
if not buf:
break
if not data:
data = buf
else:
data = data + buf
face_locations = face_recognition.face_locations(data)
face_encodings = face_recognition.face_encodings(data, face_locations)
But I get the error Expected writable numpy.ndarray with shape set.
What do I need to do to get it to work?
I forgot to load the image first. I tried it like so:
image = face_recognition.load_image_file(data)
But that gave an embedded null byte error. I then wrapped the data variable in a BytesIO call, and that did it
from io import BytesIO
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect('/path/to/socket')
data = False
while True:
buf = sock.recv(4096)
if not buf:
break
if not data:
data = buf
else:
data = data + buf
image = face_recognition.load_image_file(BytesIO(data))
face_locations = face_recognition.face_locations(image)
face_encodings = face_recognition.face_encodings(image, face_locations)
Great, thanks for sharing the answer. This should be helpful to anyone trying to figure this out later.
Most helpful comment
I forgot to load the image first. I tried it like so:
But that gave an
embedded null byteerror. I then wrapped thedatavariable in aBytesIOcall, and that did it