erorr reading Rgb Images uisng imLIb2 - c

I am trying to read a raw RGBA image using imLIb2 (https://docs.enlightenment.org/api/imlib2/html/ -> according to this page it seems like they accept RGBA data for images)
#include <Imlib2.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main(int argc, char **argv)
{
/* an image handle */
Imlib_Image image;
/* load the image */
Imlib_Load_Error error;
image = imlib_load_image_with_error_return("rgba.raw", &error);
printf("load error:%d", error);
if (image)
{
imlib_context_set_image(image);
imlib_image_set_format("png");
/* save the image */
imlib_save_image("working.png");
}
else
{
printf("not loaded\n");
}
}
loading other images formats like png and Jpeg work properly but when trying to load an RGBA image I get the error "IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT". Could someone tell me if I am missing something or should add Some header to the RGBA image or should I call some more functions before opening an RGBA image?
If Imlib2 doesn't support reading RgbA images is there any alternative C-library that can read rgb image and do scaling like functions?

So this for if someone is facing the same issue
Thanks to #mark-setchell for contributing!!
magickcore Api is an alternative C-library that can be used to perform functions on raw RGB.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <magick/ImageMagick.h>
int main(int argc, char **argv)
{
ExceptionInfo
exception;
Image
*image,
*images,
*resize_image,
*thumbnails;
ImageInfo
*image_info;
/*
Initialize the image info structure and read an image.
*/
InitializeMagick(NULL);
GetExceptionInfo(&exception);
image_info = CloneImageInfo((ImageInfo *)NULL);
image_info->size = "1920x1080";
image_info->depth = 8;
(void)strcpy(image_info->filename, "image.rgba");
images = ReadImage(image_info, &exception);
if (images == (Image *)NULL)
exit(1);
resize_image = MinifyImage(images, &exception);
if (resize_image == (Image *)NULL)
printf("error \n");
DestroyImageInfo(image_info);
DestroyMagick();
return (0);
}
for reading raw images the depth and the WxH have to be specified for the image. the above is a very small example for reducing the size in half. (https://imagemagick.org/script/magick-core.php).

Related

VLC Application can read 360 degree video bit not the C code instance

I have been trying to read a 360 degree video with a vlc instance and it just is not working.
The application itself can read the file but not when I use the code below ( by not reading, I mean I cannot drag the video and change viewpoints when I use the code below)
`
#include <stdio.h>
#include <stdlib.h>
#include </usr/include/vlc/vlc.h>
int main(int argc , char **argv)
{
libvlc_instance_t *instance;
libvlc_media_player_t *mediaplayer;
libvlc_media_t *media;
instance=libvlc_new(0,NULL);
media=libvlc_media_new_path(instance,"playlist/360_video.mp4");
mediaplayer=libvlc_media_player_new_from_media(media);
libvlc_media_release(media);
libvlc_media_player_play(mediaplayer);
sleep(60);
libvlc_media_player_stop(mediaplayer);
libvlc_media_player_release(mediaplayer);
libvlc_release(instance);
return 0;
}
`
My guess is that the instance cannot properly read the projection of the video as equirectangular that's why it display a rectangular projection.

Problem with writing rotated image as a jpeg file

In the main part, I rotated the image. Then I wrote a code for writing my image to in project file as a jpeg file. I couldn't do it.
Here is my code:
They are some definitions and libraries I used. (I also added standard libraries.)
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#define CHANNEL_NUM 3
int main() {
.
.
.
write(&out_image); // calling by reference
}
After this part, I want to write my image as a jpg file. So this is the writing part:
int write(unsigned char *rgb_image)
{
int width =400;
int height = 400;
rgb_image = malloc(width*height*CHANNEL_NUM);
stbi_write_jpg("rotated_image", width, height, CHANNEL_NUM, rgb_image, width*CHANNEL_NUM);
return 0;
}
I am not sure about the second part so I share it with you. By the way, I don't get any errors in both functions. (main and write)
If you want the full code, let me know in the comment section. I can share my main function too.

Magickcore can't set/get a single pixel

I am using MagickCore in imagemagick Q8 and I can't set specific pixel, this is my code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <magick/MagickCore.h>
#include <string.h>
int main(int argc,char **argv)
{
Image *imagen;
ImageInfo *imagen_info;
ExceptionInfo *exception;
PixelPacket *q;
MagickCoreGenesis(*argv,MagickTrue);
exception=AcquireExceptionInfo();
imagen_info = AcquireImageInfo();
(void) CopyMagickString(imagen_info->filename,argv[1],MaxTextExtent);
ReadImage(imagen_info, exception);
q = GetAuthenticPixels(imagen,0,0,1,1,exception);
q->red = 255;
q->green = 123;
q->blue = 220;
SyncAuthenticPixels(imagen,exception);
/* Write the image then destroy it. */
WriteImage(imagen_info, imagen);
DestroyImage(imagen);
DestroyExceptionInfo(exception);
MagickCoreTerminus();
return 0;
}
I am trying to read an image from a file and then edit a pixel and then save image to disk.
What am I doing wrong?
From the example provided, your imagen variable remains in a NULL pointer. It should be assigned by the return value of ReadImage.
imagen = ReadImage(imagen_info, exception);
The only other issue I see would be the assignment of color values on the PixelPacket. Assuming your working with RGB, you would need to calculate the Quantum color value.
q->red = 255 * QuantumRange;
q->green = 123 * QuantumRange;
q->blue = 220 * QuantumRange;
Note: this will issue a compiler warning, see docs for working with colors

uEye Camera and OpenCV Memory Access

I am using a 35MM EO Megapixel Fixed FL Lens Edmund Optics camera, OpenCV 2.4.6, and Ubuntu 12.04 LTS as my development environment. I am also using C to develop, not C++. The camera has an API that I am following, and I believe I have set everything up correctly. I initialize the camera, set memory locations, and freeze the video. I then use OpenCV to get the image from memory, but my image is nothing like what it should be (may be seen below). Is my image data pulling data from a junk memory location? How can I access the image saved by "is_FreezeVideo" for image processing done by OpenCV? The image that is printed out can be seen here http://i.imgur.com/kW6aqB3.png
The code I am using is below.
#include "../Include/Camera.h"
#include <wchar.h>
#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
//#include <opencv2/opencv.hpp>
#include <ueye.h>
// uEye variables
HIDS m_hCam; // handle to room
HWND m_hWndDisplay; // handle to diplay window
int m_Ret; // return value of uEye SDK functions
int m_nColorMode = 0; // Y8/RGB16/RGB24/REG32
int m_nBitsPerPixel=8; // number of bits needed store one pixel
int m_nSizeX = 1280; // width of video
int m_nSizeY = 1024; // height of video
int m_lMemoryId; // grabber memory - buffer ID
char* m_pcImageMemory; // grabber memory - pointer to buffer
int m_nRenderMode = IS_RENDER_FIT_TO_WINDOW; //render mode
void getAzimuth(){
}
void getElevation(){
}
void initializeCamera(){
if (m_hCam !=0 ) {
//free old image mem.
is_FreeImageMem (m_hCam, m_pcImageMemory, m_lMemoryId);
is_ExitCamera (m_hCam);
}
// init room
m_hCam = (HIDS) 0; // open next room
m_Ret = is_InitCamera (&m_hCam, NULL); // init room
if (m_Ret == IS_SUCCESS) {
// retrieve original image size
SENSORINFO sInfo;
is_GetSensorInfo (m_hCam, &sInfo);
m_nSizeX = sInfo.nMaxWidth;
m_nSizeY = sInfo.nMaxHeight;
printf("Width: %d Height: ", m_nSizeX, m_nSizeY);
// setup the color depth to the current windows setting
is_GetColorDepth (m_hCam, &m_nBitsPerPixel, &m_nColorMode);
is_SetColorMode (m_hCam, m_nColorMode);
//printf ("m_nBitsPerPixel=%i m_nColorMode=%i \n", m_nBitsPerPixel, IS_CM_BAYER_RG8);
// memory initialization
is_AllocImageMem (m_hCam, m_nSizeX, m_nSizeY, m_nBitsPerPixel, &m_pcImageMemory, &m_lMemoryId);
//set memory active
is_SetImageMem (m_hCam, m_pcImageMemory, m_lMemoryId);
// display initialization
is_SetImageSize (m_hCam, m_nSizeX, m_nSizeY);
is_SetImagePos(m_hCam, 0, 0);
is_SetDisplayMode (m_hCam, IS_SET_DM_DIB);
} else {
printf("No Camera Initialized! %c", 10);
}
if (m_hCam !=0) {
INT dummy;
char *pMem, *pLast;
double fps = 0.0;
if (is_FreezeVideo (m_hCam, IS_WAIT) == IS_SUCCESS) {
m_Ret = is_GetActiveImageMem(m_hCam, &pLast, &dummy);
m_Ret = is_GetImageMem(m_hCam, (void**)&pLast);
}
IplImage* tmpImg = cvCreateImageHeader (cvSize (m_nSizeX, m_nSizeY), IPL_DEPTH_8U, 1);
tmpImg->imageData = &m_pcImageMemory;
cvNamedWindow("src",1);
cvShowImage("src",tmpImg);
cvWaitKey(0);
}
}
Thanks
You need to use is_ImageFile function to save the image file to a filename.You can see the sample example from the is_ImageFile function.You can save it to the format(bmp,png,jpeg) you need.
regards,
Sreenivas
The problem was the camera properties. After setting brightness and other properties, we now get an actual image

libharu memory allocation failed while loading image

I have some C code trying to use libharu. Although I can use every function of this library (even UTF8) I can hardly draw images. Here is some very basic code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <setjmp.h>
#include "hpdf.h"
jmp_buf env;
#ifdef HPDF_DLL
void __stdcall
#else
void
#endif
error_handler (HPDF_STATUS error_no,
HPDF_STATUS detail_no,
void *user_data)
{
printf ("ERROR: error_no=%04X, detail_no=%u\n", (HPDF_UINT)error_no,
(HPDF_UINT)detail_no);
longjmp(env, 1);
}
int main (int argc, char **argv)
{
HPDF_Doc pdf;
HPDF_Font font;
HPDF_Page page;
char fname[256];
HPDF_Image image;
strcpy (fname, argv[0]);
strcat (fname, ".pdf");
pdf = HPDF_New (error_handler, NULL);
if (!pdf) {
printf ("error: cannot create PdfDoc object\n");
return 1;
}
/* error-handler */
if (setjmp(env)) {
HPDF_Free (pdf);
return 1;
}
font = HPDF_GetFont (pdf, "Helvetica", NULL);
page = HPDF_AddPage (pdf);
HPDF_Page_SetWidth (page, 550);
HPDF_Page_SetHeight (page, 500);
image = HPDF_LoadPngImageFromFile (pdf, "img.png");
HPDF_SaveToFile (pdf, fname);
HPDF_Free (pdf);
return 0;
}
When I compile this I have ERROR: error_no=1015, detail_no=0. I have found a similar post in stackoverflow: this. However although original poster said the problem is solved it hardly helped mine. I moved img.png to a folder and recompiled the file. Changed the code that says /home/name/path/to/img.png which is the direct path to image. Nothing works. I "always" have the same error, but when I change the name of file I have ERROR: error_no=1017, detail_no=2 which basicly means program cannot find image (according to reference of libharu) So I deduce that program finds img.png; but, it's strange but, cannot allocate the necessary memory. Which is weird because I cannot see any reason for this program not to allocate memory. I have every kind of permission.
I am using GCC 4.7.2 under Ubuntu Quantal Quetzal and libharu 2.3.0 RC2. Thank you for your help.
Hello Equalities of polynomials .
I also encountered the same problem when i integrated the haru sdk in my macOS environment.
The error_handler returned ERROR: error_no=1017, detail_no=2,and then i checked the official document for haru at http://libharu.sourceforge.net/error_handling.html query 0x1017 indicates that the file failed to open, so i suspect that the second parameter of the HPDF_LoadPngImageFromFile method needs to pass an exact png image file path, so after I modified it, the problem was solved, and I hope to help you.
code ad follow:
char filename1[255];
strcpy(filename1, "/Users/xx/Downloads/lusaceg.com.png");
image = HPDF_LoadPngImageFromFile (pdf, filename1);
Faithfully yours.

Resources