Is it correct to remove that line of cv2.imencode and place the file writing and return True inside the if result: block like this?