Is there a way to squash
the image instead of cropping
the image. get_features_from_image()
crops the image. The Data Input Block in EI Studio allows squashing
.
with ImageImpulseRunner("demo-linux-x86_64-v2023.eim") as runner:
features, cropped = runner.get_features_from_image(img)
louis
February 10, 2023, 9:21am
#2
Hello @MMarcial ,
Good question, we’ve been speaking about that in the past but I’m not sure it’s been implemented.
Let me have a deeper look at the code, if it’s not I’ll create an issue.
Best,
Louis
louis
February 10, 2023, 9:34am
#3
Hello @MMarcial ,
So indeed, it is missing from the function:
while not self.closed:
success, img = self.videoCapture.read()
if success:
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
features, cropped = self.get_features_from_image(img)
res = self.classify(features)
yield res, cropped
# This expects images in RGB format (not BGR)
def get_features_from_image(self, img, crop_direction_x='center', crop_direction_y='center'):
features = []
EI_CLASSIFIER_INPUT_WIDTH = self.dim[0]
EI_CLASSIFIER_INPUT_HEIGHT = self.dim[1]
in_frame_cols = img.shape[1]
in_frame_rows = img.shape[0]
factor_w = EI_CLASSIFIER_INPUT_WIDTH / in_frame_cols
factor_h = EI_CLASSIFIER_INPUT_HEIGHT / in_frame_rows
I have not tried the following modification but that’s how I’d do it:
Replace
resized = cv2.resize(img, resize_size, interpolation = cv2.INTER_AREA)
by
resized = cv2.resize(img, (EI_CLASSIFIER_INPUT_WIDTH, IEI_CLASSIFIER_INPUT_HEIGHT), interpolation = cv2.INTER_AREA)
Feel free to use other resize method but I’ve figured over time that INTER_AREA is usually the one giving the best results/performance.
Then get rid of the crop conditions below (between lines 93 and 111).
Finally just use:
cropped = resized
Let me know if that works, I’ll create an internal issue so we can natively support that.
Best,
Louis