Load jpegs taken by H7+ for post-processing

The squashing of the image loading bug and the new TF code, both of them fixed in the newest firmware by @kwagyeman , make this minimal code run fine with images generated by the board (no need for img.to_rgb565() anymore):

#import libraries
import image, os, tf, pyb
#import mobilenet model and labels
mobilenet = "trained.tflite"
labels = [line.rstrip('\n') for line in open("labels.txt")]

#scan jpegs on card
files=os.listdir()
jpegs=[files for files in files if "jpg" in files]

#open and classify each jpeg
for jpeg in jpegs:
    print("Loading:",jpeg)
    img=image.Image(jpeg,copy_to_fb=True)
    #starting classification
    print("classifying image", jpeg, "with tensorflow lite...")
    for obj in tf.classify(mobilenet, img, min_scale=1, scale_mul=0.5, x_overlap=0.5, y_overlap=0.5):
        predictions_list = list(zip(labels, obj.output()))
        print(predictions_list)

I will create another thread for loading other images (not generated by board)

Hello,
it seems that I regularly run into problems when wanting to post-process images with the board.
I recently wanted to crop a JPEG taken with the board, using this code:

import sensor, image, time, os, pyb, machine, sys

#x,y,w,h tuple
roi1=(1296,0,648,486)

#combine rois into list
rois=[roi1]

if not "crop" in os.listdir(): os.mkdir("crop")

#scan jpegs on card
files=os.listdir()
jpegs=[files for files in files if "jpg" in files]

#open each jpeg
for jpeg in jpegs:
    print("Loading:",jpeg)
    img=image.Image(jpeg,copy_to_fb=True)

    for roi_temp in rois:
        #check presence of img_s
        try:
            img_s
        except NameError:
            img_s_exists = False
        else:
            img_s_exists = True
        if(not img_s_exists):
            img_s=image.Image(roi_temp[2],roi_temp[3],sensor.RGB565,copy_to_fb=True)
        print("roi temp:",roi_temp)
        img.to_rgb565(roi=roi_temp,copy=img_s)
        img_s.save("crop/"+jpeg+"_"+str(roi_temp[0])+"_"+str(roi_temp[1])+"_"+str(roi_temp[2])+"_"+str(roi_temp[3])+".jpg")

However, all I get are blue and yellow banded images:
269.jpg_0_0_648_486
Am I doing something wrong?

Note that this often happens only with the first loaded picture. Sample pictures to reproduce the bug are here:


Which firmware are you on? There was an issue with JPEG decoding we only recently fixed.

I took the pictures with a 4.2.3 firmware board and ran the crop script on the same board directly thereafter.
I am wondering whether there is a better way to achieve the same intended result: a crop of the original image which replicates the entire image processing pipeline of the H7+. Would that result theoretically be the same as if the original image had been saved as JPEG from the same region with sensor windowing?

Yeah, I implemented support for jpeg cropping but this depends on decompression and compression working. In general… using jpegs is a bad idea for performance. BMP would be better.

So how would you recommend that I crop pictures with the board?

I’ll try to check this in a bit.

After several more trials, my tests bear out that it is only the first picture that is loaded in the sequence of pictures present on the card (I use a for loop to load them sequentially) that has problems, and this is the range of problems that it can get (a rare few were correctly saved):


It does not matter what picture it is - only that it is the first, because when I duplicated the first picture in the filesystem, it was saved fine the second time it was loaded with a different name.
The first picture always needs “Warning: JPEG/PNG too big! Trying framebuffer transfer using fallback method!”

The error is slightly different now that I installed firmware 4.3.0:

Great!

standing by to test any new firmware :slight_smile:

Finally have some more time to work on OpenMV now.

Hi there, sorry to be nosy… any workaround so far maybe?

I’ve been working on something since you’ve been asking consistently. Should be done by the end of the weekend.

Hardware jpeg is implemented. imlib: Enable hardware JPEG decoder. by kwagyeman · Pull Request #1604 · openmv/openmv · GitHub

Code is clear and tested. Any issues you have should be taken care of.