You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to build a face recognition system and I chose streamlit as my frontend UI to make API requests. I am using webrtc_streamer class to capture image live camera feed and when I try to capture a frame and convert it into numpy array using cv2.imencode() or even when I try to convert it into image bytes using tobytes() function I am not able to do it because webrtc-streamer class doesn't have tobytes() attribute. Is there any fix such that my image capture from webrtc_streamer will be a numpy array class so that I can make the API call to flask server possible?
deflogin_page():
st.title('User Login with Face ID')
st.write('Use the camera feed below to capture your face image for login.')
webrtc_streamer(
key="streamer",
video_frame_callback=transform,
sendback_audio=False
)
ifst.button('Login'):
# Perform face recognition and login process here# Convert the image to bytes_, buffer=cv2.imencode('.jpg', image_capture.frame)
image_bytes=buffer.tobytes()
# image_bytes = image_capture.frame.tobytes()# Send the image to the recognize_face API endpoint# Convert the image to JPEG format# image_jpg = cv2.imencode('.jpg', image_capture.frame)[1].tobytes()# Send the image to the recognize_face API endpointresponse=requests.post('http://localhost:5000/recognize_face', data=image_bytes)
# Get the result from the responseresult=response.json()
There is also an alternative method I have tried
classImageCapture(VideoTransformerBase):
def__init__(self):
self.frame=Nonedeftransform(self, frame):
img=frame.to_ndarray(format="bgr24")
returnframedeflogin_page():
st.title('User Login with Face ID')
st.write('Use the camera feed below to capture your face image for login.')
image_capture=ImageCapture()
webrtc_streamer(
key="streamer",
video_frame_callback=transform,
sendback_audio=False
)
ifst.button('Login'):
# Perform face recognition and login process here # image_bytes = image_capture.frame.tobytes()# Send the image to the recognize_face API endpointresponse=requests.post('http://localhost:5000/recognize_face', data=image_bytes)
# Get the result from the responseresult=response.json()
Both the methods are giving the following errors:
First method Error: cv2.error: OpenCV(4.9.0) /io/opencv/modules/imgcodecs/src/loadsave.cpp:1121: error: (-215:Assertion failed) !image.empty() in function 'imencode'
Second method Error: AttributeError: 'WebRtcStreamerContext' object has no attribute 'tobytes'
The text was updated successfully, but these errors were encountered:
sandeshkatakam
changed the title
webrtc_streamer doesn't have attribute tobytes() to conver the captured image to img_bytes and make an API call
webrtc_streamer doesn't have attribute tobytes() to convert the captured image to img_bytes and make an API call
May 16, 2024
I am trying to build a face recognition system and I chose streamlit as my frontend UI to make API requests. I am using webrtc_streamer class to capture image live camera feed and when I try to capture a frame and convert it into numpy array using cv2.imencode() or even when I try to convert it into image bytes using tobytes() function I am not able to do it because webrtc-streamer class doesn't have tobytes() attribute. Is there any fix such that my image capture from webrtc_streamer will be a numpy array class so that I can make the API call to flask server possible?
There is also an alternative method I have tried
Both the methods are giving the following errors:
cv2.error: OpenCV(4.9.0) /io/opencv/modules/imgcodecs/src/loadsave.cpp:1121: error: (-215:Assertion failed) !image.empty() in function 'imencode'
AttributeError: 'WebRtcStreamerContext' object has no attribute 'tobytes'
The text was updated successfully, but these errors were encountered: