I'm trying to take photos with OpenCV on my Raspberry Pi, but I'm running into an encoding error "UnicodeEncodeError". The specific error indicates that the character '\udce1' cannot be represented with UTF-8 encoding.
Additional details:Error that pops up:
%Run -c $EDITOR_CONTENT
PROBLEM IN THONNY'S BACK-END: Exception while handling 'Run' (UnicodeEncodeError: 'utf-8' codec can't encode character '\udce1' in position 29: surrogates not allowed).
See Thonny's backend.log for more info.
Process ended with exit code 1
System information:
Additional details:
- I have installed OpenCV successfully.
I can take photos with the `libcamera-still` command.
The error appears when running my Python code to take a photo with OpenCV.
I have checked my operating system's language and region settings, and it is set to UTF-8.
I have reviewed my code carefully and find no unusual characters.
Code:
import cv2# Initialize the cameracap = cv2.VideoCapture(0)# Capture an imageret, frame = cap.read()# Display the image in a windowcv2.imshow('Photo', frame)# Save the imagecv2.imwrite('image.jpg', frame)# Waits for a key to be pressedcv2.waitKey(0)# Release the cameracap.release()# Close all windowscv2.destroyAllWindows()
%Run -c $EDITOR_CONTENT
PROBLEM IN THONNY'S BACK-END: Exception while handling 'Run' (UnicodeEncodeError: 'utf-8' codec can't encode character '\udce1' in position 29: surrogates not allowed).
See Thonny's backend.log for more info.
Process ended with exit code 1
System information:
- Raspberry Pi 4B
Thonny IDE
OpenCV 4.6.0
- Help to identify the cause of the coding error.
Suggestions to solve the problem and be able to take photos with OpenCV on my Raspberry Pi.
Statistics: Posted by Baladier — Mon Apr 08, 2024 4:33 am