Send cv2 video stream for face recognition

2024/11/15 22:19:36

I'm struggling with a problem to send a cv2 videostream (webcam) to a server (which shall be used later for face recognition).

I keep getting the following error for the server:

Traceback (most recent call last):File "server.py", line 67, in <module>small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
cv2.error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) in function 'resize'
> Overload resolution failed:
>  - src data type = 18 is not supported
>  - Expected Ptr<cv::UMat> for argument 'src'

The server looks like this:

if client_socket:while True:packet = client_socket.recv(4 * 1024)frame = np.array(packet)small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)rgb_small_frame = small_frame[:, :, ::-1]

And here's the client:

while True:vid = cv2.VideoCapture(0)while vid.isOpened():time.sleep(0.5)img, frame = vid.read()frame = imutils.resize(frame, 4 * 1024)a = pickle.dumps(frame)message = struct.pack("Q", len(a)) + atry:client_socket.sendall(message)except Exception as e:print(e)raise Exception(e)

Anyone any idea?

As it's a data stream of bytes, I tried to include for instance the sleep function to allow for more processing. Also tried to isolate the client's picture but also got errors.

Answer

There are several issues with your code. Regarding your question: You are passing a byte string to resize:

import cv2
import numpy as npcv2.resize(np.array(b"Hello"), (0, 0), fx=0.25, fy=0.25)

Output:

cv2.error: OpenCV(4.5.4) :-1: error: (-5:Bad argument) in function 'resize'
> Overload resolution failed:
>  - src data type = 18 is not supported
>  - Expected Ptr<cv::UMat> for argument 'src'

Please consider:

  • don't use pickle for this kind of task, but compress the data to png or similar before sending it
  • pass the data length before sending the data and use it on server side to collect the complete data before uncompressing it
https://en.xdnf.cn/q/119603.html

Related Q&A

Generate all possible lists from the sublist in python [duplicate]

This question already has answers here:How to get the Cartesian product of multiple lists(20 answers)Closed 7 years ago.Suppose I have list [[a, b, c], [d, e], [1, 2]]I want to generate list where on t…

Time/frequency color map in python

Is there in native Python 3.X library or in scipy/numpy/matplolib libraries a function or their short set which could help me to draw a plot similar to this one(?):What would be an efficient way to ac…

ImageMagick is splitting the NASAs [.IMG] file by a black line upon converting to JPG

I have some raw .IMG format files which Im converting to .jpg using ImageMagick to apply a CNN Classifier. The converted images, however have a black vertical line splitting the image into two. The par…

CV2 - rectangular detecting issue

Im trying to implement an OMR using pythons CV2. As part of the code I need to find the corners of the choices box (rectangulars) however I ran into difficulty causes by the grade sheet template. In th…

Keras/TensorFlow - high acc, bad prediction

Im new to machine learning and Im trying to train a model which detects Prague city in a sentence. It can be in many word forms.Prague, PRAHA, Z Prahy etc...So I have a train dataset which consists of …

Flask-HTTPAuth: how to pass an extra argument to a function decorated with @auth.verify_password?

Heres a small Flask app authenticated with Flask-HTTPAuth. How to pass an argument (such as authentication on/off flag, or verbosity level / debug on/off flag) to a function (such as authenticate below…

AttributeError: numpy.ndarray object has no attribute split

Given a text file with one DNA sequence on each line and joining these together I now want to split the string into 5 sequences (corresponding to each of the 5 rows). This is the file source: http://ww…

How do I determine if a lat/long point is within a polygon?

I have a shapefile of all the counties that make up my state. Using the shapefile (which contains geometric for the district polygons) I was able to use geopandas to plot the shapes in a figure. I have…

How to return different types of arrays?

The high level problem Im having in C# is to make a single copy of a data structure that describes a robot control network packet (Ethercat), and then to use that single data structure to extract data …

How do I pass an array of strings to a python script as an argument?

Ive written a swift app that outputs an array of strings. I would like to import this array into a python script for further processing into an excel file via xlsxwriter, I would like to do this as an …