Spaces:
Sleeping
Sleeping
Green Doctor Deployer commited on
Commit ·
3f7ebd7
1
Parent(s): ced356b
Fix BGR to RGB color conversion for Raspberry Pi camera feed
Browse files
raspberry_pi/app_streamlit.py
CHANGED
|
@@ -80,7 +80,9 @@ if interpreter:
|
|
| 80 |
break
|
| 81 |
|
| 82 |
# 1. Preprocess
|
| 83 |
-
|
|
|
|
|
|
|
| 84 |
img = img.astype(np.float32) / 255.0
|
| 85 |
input_data = np.expand_dims(img, axis=0)
|
| 86 |
|
|
|
|
| 80 |
break
|
| 81 |
|
| 82 |
# 1. Preprocess
|
| 83 |
+
# Convert BGR (OpenCV) to RGB (Model Expectation)
|
| 84 |
+
img_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 85 |
+
img = cv2.resize(img_rgb, (width, height))
|
| 86 |
img = img.astype(np.float32) / 255.0
|
| 87 |
input_data = np.expand_dims(img, axis=0)
|
| 88 |
|
raspberry_pi/realtime_pi.py
CHANGED
|
@@ -67,8 +67,10 @@ def main():
|
|
| 67 |
break
|
| 68 |
|
| 69 |
# 3. Preprocess Frame
|
|
|
|
|
|
|
| 70 |
# Resize to model input size
|
| 71 |
-
img = cv2.resize(
|
| 72 |
# Convert to float32 and normalize if necessary (MobileNetV2 usually expects [0, 1] or [-1, 1])
|
| 73 |
# Based on training script ImageDataGenerator(rescale=1./255)
|
| 74 |
img = img.astype(np.float32) / 255.0
|
|
|
|
| 67 |
break
|
| 68 |
|
| 69 |
# 3. Preprocess Frame
|
| 70 |
+
# Convert BGR (OpenCV) to RGB (Model Expectation)
|
| 71 |
+
img_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 72 |
# Resize to model input size
|
| 73 |
+
img = cv2.resize(img_rgb, (width, height))
|
| 74 |
# Convert to float32 and normalize if necessary (MobileNetV2 usually expects [0, 1] or [-1, 1])
|
| 75 |
# Based on training script ImageDataGenerator(rescale=1./255)
|
| 76 |
img = img.astype(np.float32) / 255.0
|