Raspberry Pi Camera Module Producing Invalid Images

1.3k Views Asked by At

I am trying to use the Raspberry Pi Camera to take pictures and videos. It was all working fine for about 3 days, after which things started to go downhill. First, I noticed that the website where I was streaming the Raspberry Pi's video showed the unloaded image sign (https://www.thewindowsclub.com/wp-content/uploads/2018/06/Broken-image-icon-in-Chrome.gif). Therefore, I went back to my raspbian terminal and tried basic commands. First, I tried this:

raspistill -o /home/pi/Desktop/image.png

This worked perfectly the past few days, and I thought it worked again, until I opened the image. Image Viewer said that the image is not a PNG file at all. This was the popup:

Fatal error reading PNG image file: Not a PNG file

After looking up the error, I reinstalled the PNG library, and still no luck. So, I decided to use jpg instead. I next executed this:

raspistill -o /home/pi/Desktop/img.jpg

And... I got another error:

Error interpreting JPEG image file (Not a JPEG file: starts with 0xc5 0xdb)

After looking it up again, I used this command:

file /home/pi/Desktop/img.jpg

I got the following output:

/home/pi/Desktop/image.jpg: data

So... if the jpg file is actually a data file, what is the problem? Also, it was working perfectly for the past few days in a Python script and with the terminal... What happened now?

Some additional information: I always use xrdp to Remote Desktop from my Windows Laptop to my Raspberry Pi (4 B+). Therefore, I cannot see if the preview works or not. I am using Raspberry Pi Camera Rev. 1.3 and Raspbian Full 32-bit.

Some more important information: This error started occurring after an incident that I can't explain. I had my Windows Laptop connected to my Raspberry Pi with Remote Desktop, and I accidentally pressed the Sleep button. When I woke the laptop again, it said Remote Desktop terminated unexpectedly. I kept trying to reconnect but it wouldn't work. So, I unplugged the Raspberry Pi and plugged it in again. After I used Remote Desktop to connect to it again, it started doing this. This made me think it was a software problem, so I enabled and disabled Camera from Raspberry Pi Configuration and raspi-config, but it was no use.

I am stuck and don't know what to do. Any help would be greatly appreciated. Thank You in advance.

EDIT: The preview shows up perfectly, it's just the saving of the image that somehow gets corrupted. Is there any way to re-install raspistill?

1

There are 1 best solutions below

1
On

I had the same problem.

Installation steps: -Raspberry pi 4 B 8 Gb -RPi camera 8 MP v2.1 -Used official Raspberry pi imager app for MacOS to install the official Raspberry Pi 32 bit OS onto 32 GB card -Set up the Rpi by following all setup prompts -Ran, sudo apt update, sudo apt upgrade & sudo rpi-update in terminal and rebooted -Ran sudo rasps-config in terminaI and went to “Interfacing options” and enabled interface option P1 Camera -Shutdown and connected the raspberry pi camera to the camera interface on the board, made sure the ribbon was right way round and properly seated at the port and at the other end on the card containing the camera -Ran sudo vcgencmd get_camera in terminal and it returned “supported=1 detected=1”

Here is what I did next: -Ran raspistill -o Desktop/image.jpg in terminal, got a camera preview on screen -Ran raspivid -o Desktop/vid.h264 in terminal, got camera preview -Went to the desktop, the two files were there ,opened the jpg file with image viewer and it looks fine. Tried to open the h264 video file using VLC media player and all I got was a strip of pixelations across the top of the screen -Installed Kodi player because I thought it might be better at opening h264 video files than VLC -Installed omxplayer from terminal and tried to open the h264 video file from there - didn’t open

I then repeated installation steps above and installed the OS afresh. In the process I shutdown and I removed the camera from the port, reinserted the camera then rebooted and ran vcgencmd get_camera in terminal and it returned “supported=1 detected=1”.

Then I did the following image/video capture steps: -Ran raspistill -o Desktop/image.jpg in terminal, got a camera preview on screen -Ran raspivid -o Desktop/vid.h264 in terminal, got camera preview -Went to the desktop, the two files were there -Tried to open image.jpg and got some error message saying “Error interpreting JPEG image file (Not a JPEG file: starts with 0xc% 0xdb” -So now I could not open either the captured image file or the video file

I kept using the raspberry pi over a day or so to do other things and in the process I probably rebooted/shutdown several times. I deleted Kodi because it didn’t help and was taking up space. I may have done installation steps another time but not sure if I did. I then ran the image/video capture steps mentioned immediately above and to my surprise not only did I get the previews but I was able to open the jpg file and the h264 video file using image viewer and VLC respectively. The camera seems to function correctly. Not sure what happened. Might have been the reinstall or the installation and subsequent deletion of Kodi that did it - I guess I will never know but it looks like reinstalling OS, update, upgrade and reseating both ends of the camera ribbon cable may have done the trick.