Imread error in Raspberry pi deployment

Hello everyone!
I wrote small function, including imread(), and tried to deploy in Raspberry PI. But I got this error “The function imread uses a precompiled shared library which is not supported on the chosen target.”
Does it mean I cannot use imread() in Raspberry PI? Shall I need to use fread() or fopen() to read the image files in Raspberry system?

3 Commenti

I can't help. I have the problem that writePixel shows no result without error message
Could you confirm that you are using Raspberry Pi with a SenseHat board? https://www.mathworks.com/help/supportpkg/raspberrypiio/sense-hat.html
Joseph Neelen
Joseph Neelen il 20 Ago 2023
Spostato: Walter Roberson il 20 Ago 2023
I use Pi3B with sensehat. Its working perfect. Using MATLAB all sensehat functions are oké. Except the 8x8 LED matrix. WritePixel, wrieMessage show no result without errond massages.

Accedi per commentare.

 Risposta accettata

Walter Roberson
Walter Roberson il 4 Ago 2021
Modificato: Walter Roberson il 4 Ago 2021
Two cases:
If the file is a static file available to the matlab host, with constant name, then read the image and save it to a mat. Then in the code to be deployed, coder.load()
If the file is not a static file with fixed name, such as if it is a file from the raspberry file system (especially one with dynamic name) then use coder.ceval() to make a call to an external library routine to do the reading work, such invoking libjpeg

6 Commenti

Thank you for the answer.
The second is my case. I want to read the image files stored in the raspberry pi system.
Can I ask one more question? You suggested using coder.ceval() for reading the image file.
Is it better than using fread() or fopen() function?
fopen() is for opening a file for processing. It would be followed by fread() to read in information from the file.
Image files are rarely just plain arrays of data (PPM file format http://netpbm.sourceforge.net/doc/ppm.html comes close).
For the systems that imread() can be deployed to at all, it only supports 8 bit JPEG files. .jpg files are binary files stored in the JFIF container format (just like AVI files are a binary container format), with the image file having several binary subsections, one of which typically contains a block tagged JPEG that is data compressed with processed dct components in a particular order. In order to read the file in as an image, you have to know something about the JFIF container format in order to locate the JPEG block inside it, and then you have to understand the structure of the JPEG block and what calculations are needed to expand the compressed coefficients back into image data.
It is certainly theoretically possible to write MATLAB-level code using fopen() / fread() that can read a .jpg file; there is probably a File Exchange Contribution to do that.
However, writing your own code to do that work is time consuming, and bug prone, and not very flexible. It is typically much more productive to instead find a pre-written library such as libjpeg or libjpeg-turbo https://libjpeg-turbo.org/ or https://github.com/6by9/userland/blob/hello_mmal/host_applications/linux/apps/hello_pi/hello_mmal_jpeg/jpeg.c
Thanks a lot!
I will choose your advice of using the libjpeg library.
Hello @Walter Roberson. Im facing the same problem as @Hyoung-Bum Kim. The only extra issue is that I am completely new to C langauage programming and I dont really know how to use libjpeg or libjpeg-turbo to do the reading work instead of using imread.
My context: The images I have are .jpg to be stored on the Raspberry Pi in a static location. I have an image processing code (written in matlab).
Sorry for being a noob. Any sort of help is appreciated. Maybe a link to an example of someone using libjpeg would be great. Thank you for your time.
Is there a reason you cannot preprocess the files to become just arrays of pixel data, or at most arrays of pixel data with a size header?
@Walter Roberson, my code finally worked. I ended up using stb_image library to read the image and store the data as arrays of pixel data. What worked for me was declaring a global variable that both the c-files and matlab files can see during code generation, and the c-files where responsible for loading the global variable (3D array) with pixel data which then matlab can use.
I really had a hard time figuring things out. There are a lot of details that need to be considered before attempting to substitute imread with c-files and if you miss one of them, nothing will work.
Thank you @Walter Roberson, you gave me a starting point when you said use coder.ceval() to call external librariries. For those who have similar trouble using imread with codegen for raspberry pi, i can help you out haitham.kanj@lau.edu

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su MATLAB Support Package for Raspberry Pi Hardware in Centro assistenza e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by