opening a saved mjpeg for analysis

I’ve found a couple of topics and the example for loading a saved image to the frame buffer. (topics here, here, here )

I was getting an error … which I’m guessing is because this is supposed to be for a single jpeg of below a certain size.

But is there a way/ will this work for loading a saved/captured mjpeg for later analysis?

For some reason I’m getting a PHP error when trying to add my full code … but I replaced

# Load image
img = image.Image("/example.bmp", copy_to_fb=True)


# Load image
img = image.Image("/SP_MV_FU-853556954.mjpeg", copy_to_fb=True)

and got the error: OSError: unsupported format!

We don’t have any code to decode JPEG images, we just support compressing images and then saving them to disk or transmitting them.

Um, that said, for the next release I added a new Image Reader and Writer class that saves rae uncompressed video you can read and write. But, it’s only viewable with your OpenMV Cam. A simple python script could be used to turn the raw video stream into any other format.

Why do you need to look at the previous images you saved? This seems like a design issue. You shouldn’t need the OpenMV Cam to look at past history for any application. It’s designed to be doing real time stuff.

It would be very useful to have this feature in order to be able to debug my code on “known data” … or an already collected data set. That way I can run through my code/test without have to reproduce the experiment/ situation I want to use my camera on every time I make a change.

If the IDE could do this instead of the camera (which I didn’t think any code could be run separate from the camera, ie with the camera disconnected), that would be handy, too.

1 Like

Yeah, so, we basically have this feature coming up in the next release:

Let me know if you want it now and I can post the scripts to use it along with a binary file for it.

That looks like exactly what I need.
(Seriously, y’all are really on top of stuff …)
Can you post that somewhere that I can take a look?

K, will do tonight. Do a reminder post in about 13 hours to poke me to do it.


Load the binary using the run bootloader option. This binary is only for the M7. Attached scripts show off how to use the feature. Don’t forget to update the firmware once the new IDE/firmware comes out (end of the month likely). (823 KB)

I’ll do this today once I get on a Windows Machine (I’ve had some … hinkiness … with the IDE on OSX not recognizing the camera. Running the camera on a Windows machine works/resets everything without having to use the jumper pin option).
I’ll report back!

hrrmmm … this only seems to work with .bin files.
(and not .mjpeg … like what’s used in the Video Recording Example).

Is there a way to modify it so that it’ll work for both?
Or a way to convert mjpeg to bin?

As explained in the video this feature is recording data in my own specific file format. Its literally a raw stream of image structs from the camera memory. If you want it recorded as MJPEG you can do that to at the same time, but that will affect performance. The point of this feature was to not affect performance too much.

Um, it wouldnt be hard for me to add a tool to OpenMV IDE to convert the image stream to MJPEG/GIFs. I guess I can get that in the next release.

what video?

And yes, that would be helpful. That way a user can choose which module/ function they’d prefer and be able to still use this feature as well as export it for viewing in VLC (which is why I was recording in mjpeg instead of the *.bin format).
This is awesome.


What’s a good way to print that the video is done before starting the next loop?
That While(True) is throwing me for a loop (ha!)

I tried something like

    img = sensor.snapshot() if snapshot_source else img_reader.next_frame(copy_to_fb=True, loop=True)
    # Do machine vision algorithms on the image here.

    if loop==False: 

But that just throws an error since ‘loop’ isn’t a variable …

See our YouTube channel for a video on this feature.

As for the function, next frame returns a None object if loop is not equal to true when called at the end of the video. So just remove loop=True and then check to see if the img result is None/False.

When using the above script, I’m getting a lot of “Assertion Failed” errors which cause me to have to disconnect and reconnect the camera (through the IDE Tools menu).
I’ve also been unable to open about every third .bin file, getting an error along the lines of “unreadable file” (I can’t connect right now but I’ll edit in the actual error once I’m able).
I just also received a “Timeout error while getting firmware version!” error after the camera locked up and disconnected.
This last error seems to have bricked my camera.

Thank you

When trying to open a file, about a third of the time, I get this error: "

Traceback (most recent call last):
  File "<stdin>", line 29, in <module>
OSError: Failed to read requested bytes!
MicroPython d23b594 on 2017-07-05; OPENMV3 with STM32F765
Type "help()" for more information.

Hi, I posted another version of the IDE for windows recently that fixes a timeout issue with the IDE not allowing the camera to go off and save files before disconnecting. Are you using that fixed IDE?

Also, are you using an SD card with enough memory? GBs?

As for a bin file with an error… so, the file needs to be closed at the end. Otherwise it gets corrupted.

Anyway, the camera is unbrickable. You can always restore the firmware by following the IDE prompts.

Yes. It’s a 32GB SD Card. I’ve been periodically removing files.
I have been closing the files after every recording.

The camera, while “unbrickable” seems to require a “reset” on a Windows machine. I’ve been unable to recover the camera’s functionality using the IDE (more specifically, I’ve been unable to reload the boot-loader successfully using the IDE on OSX. It hangs at the “contacting device” prompt)

The new IDE is coming soon. I’ve already put this fixes in for learning the MTU size on the camera. I just have to write it in for the IDE.

Um, what OS do you want to work on? Mac. I should be able to cut a pre release Mac IDE with the fixes by the end of the week.

It’s a Mac … 10.11.16.

Hi, please try out the new IDE here and let me know if it fixes the issue:

Flash your OpenMV Cam M7 with this firmware (attached). (1010 KB)

I’ll try this today.
Thank you!
(seriously. you guys do great work and support. keep it up!)