Black and white
This commit is contained in:
parent
93ef52e66f
commit
e7af02cb4f
3 changed files with 34 additions and 22 deletions
|
@ -3,7 +3,7 @@
|
|||
import cv2
|
||||
import numpy as np
|
||||
|
||||
from globalVars import HEIGHT, WIDTH
|
||||
from globalVars import HEIGHT, NUM_PRESET_SPEEDS, WIDTH
|
||||
|
||||
|
||||
def extract_edge_features(frame):
|
||||
|
@ -39,17 +39,23 @@ def extract_histogram_features(frame, bins=64):
|
|||
return np.array(feature_vector)
|
||||
|
||||
|
||||
def preprocess_frame(frame):
|
||||
def preprocess_frame(frame, crf, speed):
|
||||
# Check frame dimensions and resize if necessary
|
||||
if frame.shape[:2] != (HEIGHT, WIDTH):
|
||||
frame = cv2.resize(frame, (WIDTH, HEIGHT), interpolation=cv2.INTER_NEAREST)
|
||||
|
||||
# Extract features
|
||||
edge_feature = extract_edge_features(frame)
|
||||
histogram_feature = extract_histogram_features(frame)
|
||||
|
||||
histogram_feature_image = np.full((HEIGHT, WIDTH), histogram_feature.mean()) # Convert histogram feature to image-like shape
|
||||
combined_feature = np.stack([edge_feature, histogram_feature_image], axis=-1)
|
||||
# Scale frame to [0, 1]
|
||||
compressed_frame = frame / 255.0
|
||||
|
||||
compressed_frame = frame / 255.0 # Assuming the frame is uint8, scale to [0, 1]
|
||||
return compressed_frame
|
||||
# Scale CRF and SPEED to [0, 1] (assuming they are within known bounds)
|
||||
crf_scaled = crf / 51
|
||||
speed_scaled = speed / NUM_PRESET_SPEEDS
|
||||
|
||||
# Create images with the CRF and SPEED values, filling extra channels
|
||||
crf_image = np.full((HEIGHT, WIDTH, 1), crf_scaled) # Note the added dimension
|
||||
speed_image = np.full((HEIGHT, WIDTH, 1), speed_scaled) # Note the added dimension
|
||||
|
||||
# Combine the frames with the CRF and SPEED images
|
||||
combined_frame = np.concatenate([compressed_frame, crf_image, speed_image], axis=-1)
|
||||
|
||||
return combined_frame
|
||||
|
|
Reference in a new issue