doublelotus commited on
Commit
25657f4
·
1 Parent(s): dce6539
Files changed (1) hide show
  1. main.py +7 -5
main.py CHANGED
@@ -49,11 +49,13 @@ def get_masks():
49
  if image_file.filename == '':
50
  return jsonify({"error": "No image file provided"}), 400
51
 
52
- raw_image = Image.open(image_file).convert("RGB")
53
- # Convert the PIL Image to a NumPy array
54
- image_array = np.array(raw_image)
55
- # Since OpenCV expects BGR, convert RGB to BGR
56
- image = image_array[:, :, ::-1]
 
 
57
 
58
  if image is None:
59
  raise ValueError("Image not found or unable to read.")
 
49
  if image_file.filename == '':
50
  return jsonify({"error": "No image file provided"}), 400
51
 
52
+ # Read image file using OpenCV-style approach (similar to cv2.imread)s
53
+ # Convert the image file to a NumPy array using OpenCV
54
+ file_bytes = np.fromstring(image_file.read(), np.uint8)
55
+ image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
56
+
57
+ # Convert BGR to RGB using OpenCV (similar to cv2.cvtColor)
58
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
59
 
60
  if image is None:
61
  raise ValueError("Image not found or unable to read.")