I'm grabbing a JPEG image into the Frame Buffer at FRAMESIZE_SVGA (i.e. 800x600) and then attempting to convert it to a bitmap, RGB888, via a call to frame2bmp(). Sometimes it works, sometimes not. I print out some info, such as how many bytes it captured into the Frame Buffer, which looks fairly small to me (like shown below), but the error I get when it fails is like this:
SUCCESS Acquiring a single JPEG frame.
JPEG Frame size = 14400 bytes
Trying to convert the acquired single frame to BMP format using frame2bmp().
[E][esp_jpg_decode.c:108] esp_jpg_decode(): JPG Decompression Failed! Device error or wrong termination of input stream
What might be causing the problem? What might I do to avoid the error, especially since it seems so random.
What causes this JPG Decompression failure?
-
- Posts: 21
- Joined: Mon Sep 14, 2020 1:21 am
-
- Posts: 9757
- Joined: Thu Nov 26, 2015 4:08 am
Re: What causes this JPG Decompression failure?
Hard to say, possibly signal integrity issues on the line to your camera.
-
- Posts: 21
- Joined: Mon Sep 14, 2020 1:21 am
Re: What causes this JPG Decompression failure?
"signal integrity issues on the line to your camera"
On the line to the camera? The camera is directly plugged into the ESP32 board. There's no "line to the camera".
Plus, I get a success return when I actually grab the image from the camera. It's when I'm doing the frame2bmp() call that I get the error. It SHOULD be simply accessing the data in the Frame Buffer and storing new data (bitmap data) into another section of memory. It shouldn't be accessing the camera at all at that point in my code.
On the line to the camera? The camera is directly plugged into the ESP32 board. There's no "line to the camera".
Plus, I get a success return when I actually grab the image from the camera. It's when I'm doing the frame2bmp() call that I get the error. It SHOULD be simply accessing the data in the Frame Buffer and storing new data (bitmap data) into another section of memory. It shouldn't be accessing the camera at all at that point in my code.
-
- Posts: 9757
- Joined: Thu Nov 26, 2015 4:08 am
Re: What causes this JPG Decompression failure?
Sure. The point is that the JPEG data is just raw data when you retrieve it from the camera; if a bit flips, the receiving code won't notice. (And in a bmp, you probably also won't notice as it may only affect one pixel.) However, if you try to decode the JPEG stream, the decoder will notice it's corrupted and fail.
-
- Posts: 1
- Joined: Thu Oct 01, 2020 12:06 pm
Re: What causes this JPG Decompression failure?
Did you figure out what caused the error? I am getting the exact same error trying to format a JPEG to a bitmap to grab the RGB888 pixel data
-
- Posts: 21
- Joined: Mon Sep 14, 2020 1:21 am
Re: What causes this JPG Decompression failure?
widepeepoHappy
I think I found the source of the problem. I did some testing by saving the original JPEG file to a file. When there's no problem with the conversion to bitmap the JPEG file looks just fine (using a paint program to view it). But when that conversion error happens the JPEG files itself looks bad. It's still a JPEG image of the correct size (height and width) but only a portion of the image is correct. It's always an upper portion that's correct, maybe half, a third, or just a few rows of pixel data, but the rest, the lower portion, is either blank or garbage.
OBSERVATION
So my first observation is that AN error actually occurs during the capture of the JPEG image, ...
but it doesn't TELL YOU that an error has occurred. You still get a non-NULL pointer to the frame buffer returned from the function call. I've always taken that to mean that there were no problems in the esp_camera_fb_get(), but apparently not.
QUESTION
Is there some error variable or SOMETHING that I should be checking after that function call to see if some error may have occurred? None of the sample programs that I've come across show any kind of error checking.
SUGGESTION
There SHOULD be some indication of the failure that (actually) occurs during the esp_camera_fb_get().
Getting a failure from the conversion function just confuses the situation. The actual error occurs during esp_camera_fb_get(), not esp_camera_fb_get().
FURTHER TEST / ANOTHER OBSERVATION
I have several ESP32-CAMs so I tried a different one and I encountered no conversion errors. Taking a close look at the one that experienced the failures I noticed a very slight kink in the very short ribbon cable that connects the camera itself to the board. Since that ribbon cable causes the camera to not lay flat against the board (and easily jiggle while taking a picture) I had adopted the approach of manually holding the camera flat against the board whenever I'm taking a picture.
CONCLUSION?
I'm concluding that my repeated pressing on the camera to hold it steady against the board eventually caused that tiny kink in the ribbon cable and that kink resulted in a crack in at least one of the wires in the cable and that crack caused an intermittent disconnect of that line between the camera and the board.
WHAT YOU MIGHT DO?
So, maybe have a close look at that ribbon cable on your board. Let me know if you see the same symptoms.
WHAT THE MANUFACTURER MIGHT DO?
My board is an ESP32-CAM, which is not manufactured by espressif, so it might (just) be a problem with whoever manufactured my particular board. But maybe it's a similar problem with espressif boards. I'm thinking that there needs to be some change in the board design so that the camera is assured to lay nice and flat all the time.
I think I found the source of the problem. I did some testing by saving the original JPEG file to a file. When there's no problem with the conversion to bitmap the JPEG file looks just fine (using a paint program to view it). But when that conversion error happens the JPEG files itself looks bad. It's still a JPEG image of the correct size (height and width) but only a portion of the image is correct. It's always an upper portion that's correct, maybe half, a third, or just a few rows of pixel data, but the rest, the lower portion, is either blank or garbage.
OBSERVATION
So my first observation is that AN error actually occurs during the capture of the JPEG image, ...
Code: Select all
camera_fb_t * CameraFrameBuffer = esp_camera_fb_get();
QUESTION
Is there some error variable or SOMETHING that I should be checking after that function call to see if some error may have occurred? None of the sample programs that I've come across show any kind of error checking.
SUGGESTION
There SHOULD be some indication of the failure that (actually) occurs during the esp_camera_fb_get().
Getting a failure from the conversion function just confuses the situation. The actual error occurs during esp_camera_fb_get(), not esp_camera_fb_get().
FURTHER TEST / ANOTHER OBSERVATION
I have several ESP32-CAMs so I tried a different one and I encountered no conversion errors. Taking a close look at the one that experienced the failures I noticed a very slight kink in the very short ribbon cable that connects the camera itself to the board. Since that ribbon cable causes the camera to not lay flat against the board (and easily jiggle while taking a picture) I had adopted the approach of manually holding the camera flat against the board whenever I'm taking a picture.
CONCLUSION?
I'm concluding that my repeated pressing on the camera to hold it steady against the board eventually caused that tiny kink in the ribbon cable and that kink resulted in a crack in at least one of the wires in the cable and that crack caused an intermittent disconnect of that line between the camera and the board.
WHAT YOU MIGHT DO?
So, maybe have a close look at that ribbon cable on your board. Let me know if you see the same symptoms.
WHAT THE MANUFACTURER MIGHT DO?
My board is an ESP32-CAM, which is not manufactured by espressif, so it might (just) be a problem with whoever manufactured my particular board. But maybe it's a similar problem with espressif boards. I'm thinking that there needs to be some change in the board design so that the camera is assured to lay nice and flat all the time.
-
- Posts: 9757
- Joined: Thu Nov 26, 2015 4:08 am
Re: What causes this JPG Decompression failure?
FYI, from what I understand there is no way for the hardware to figure out there is an error in the communication until the JPEG is actually decoded, as there is no error checking logic or anything in the datastream. We just get a stream of raw data from the camera, and if a bit flips or a clock cycle gets lost somehow, there is no way to notice that from the hardware behaviour.
Who is online
Users browsing this forum: No registered users and 20 guests