Image Classification using OpenMV Cam H7 Plus

Hi there, I am building an image classification model using Edge Impulse and OpenMV Cam H7 Plus.
I have collected images using the camera and OpenMV IDE and classified into different classes. Based on that I trained the Edge Impulse Model. Now I want to classify the images in real time using the OpenMV Cam on OpenMV IDE.
Please guide me through this!
Thanks in advance.

Edge Impulse has a guide for this on their website… OpenMV - Edge Impulse Documentation

1 Like

Got it, now I am able to classify the images in real time using the camera.
Now I want to store the images captured into different folders either on the camera (using SD card) or on the PC according to their class/labels.
(Like if the image is clear and readable I want to store it otherwise reject and click another)
Can you please suggest some way to do it?
Thank you so much for your help!!

1 Like

Hi @Dhruhi,
If you trying to do binary classification. I made you an example:



import sensor, image, time, os, tf, uos, gc

sensor.reset()                         # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565)    # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)      # Set frame size to QVGA (320x240)
sensor.set_windowing((240, 240))       # Set 240x240 window.
sensor.skip_frames(time=2000)          # Let the camera adjust.

net = None
labels = None

try:
    # load the model, alloc the model file on the heap if we have at least 64K free after loading
    net = tf.load("trained.tflite", load_to_fb=uos.stat('trained.tflite')[6] > (gc.mem_free() - (64*1024)))
except Exception as e:
    print(e)
    raise Exception('Failed to load "trained.tflite", did you copy the .tflite and labels.txt file onto the mass-storage device? (' + str(e) + ')')

try:
    labels = [line.rstrip('\n') for line in open("labels.txt")]
except Exception as e:
    raise Exception('Failed to load "labels.txt", did you copy the .tflite and labels.txt file onto the mass-storage device? (' + str(e) + ')')

while(True):

    img = sensor.snapshot()

  
    obj = (net.classify(img, min_scale=1.0, scale_mul=0.5, x_overlap=0.0, y_overlap=0.0))[0]
    if obj.output()[1] > 0.5:
        img.save("Class1/frame.jpg")
    else:
        img.save("Class2/frame.jpg")
   
    


1 Like

Hey @BehicMV ,
Thank you for your reply, will test the code if it works fine for my application.
I am building an application for automating the scanning of answer sheets. For that, I am trying to classify the images between 5 classes ( i.e, Printed, Handwritten, Printed with Object, Handwritten with object, Blurred). The project requires Clear images whether Printed or Handwritten, anything else is rejected.
After a set of images are collected they will be stored in a folder or converted into a pdf.
This is the whole scenario, any suggestions or ideas are welcome.
Thanks!