I am working on a project for which I need to combine few images, The end result is an Image with resolution (120849, 296). In my Project, I am trying to save this image to my local disk in the jpg format using the imwrite() function. But it is not working for me. No error or exception is given by my current code.
The only solution that worked for me was this one.
Solution 1
Which is not what I want. Can anyone tell me, how can I save the image in jpg format in OpenCV 4.5.5 using compression parameters? I think this might be the solution that I need.
Related
I'm developing an OCR app for Android using JNI and a code developed under C++ using OpenCV and Tesseract. It will be used to read a badge with an alphanumeric ID from a photo taken by the app.
I developed an code which handle with the preprocess of the image, in order to obtain a "readable image" as the one below:
I wrote the following function for "reading" the image using tesseract:
char* read_text(Mat input_image)
{
tesseract::TessBaseAPI text_recognizer;
text_recognizer.Init("/usr/share/tesseract-ocr/tessdata", "eng", tesseract::OEM_TESSERACT_ONLY);
text_recognizer.SetVariable("tessedit_char_whitelist", "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
text_recognizer.SetImage((uchar*)input_image.data, input_image.cols, input_image.rows, input_image.channels(), input_image.step1());
text_recognizer.Recognize(NULL);
return text_recognizer.GetUTF8Text();
}
The expected result is "KQ 978 A3705", but what I get is "KO 978 H375".
I did all the recommendations for improving the quality of the image from https://github.com/tesseract-ocr/tesseract/wiki/ImproveQuality. In addition, reading the docs from https://github.com/tesseract-ocr/docs, I tryed using an approximation of the images using polygons in order to get "better" features. The image I used is one like this:
With this image, I get "KO 978 A3705". The result is clearly better than the previous one, but is not fine.
I think that the processed image I pass to tesseract is fine enought to get a good result and I don't get it. I don't know what else to do, so I ask you for ideas in order to solve this problem. I need an exact result and I think I could get it with the processed image I get. Ideas please! =)
I noticed that with some dilations, the result ORC result is improved incredible well! For me, it was the solution
I am creating a pdf using libharu in C++ (compiled as a .cgi) that features .png images.
The code is fine, but my pdf's are ridiculously oversized.
Each page features one image of around 30kb and around 4 text characters in libharu's system font. If I open a 20 page output file of 25mb and "print" it to a file in my operating system it becomes 256kb or so with no visible change to the images.
I think the issue is related to libharu because this guy see's it too, here. He is using php so, libharu as a compiled .cgi. (my C++ code is also compiled .cgi, linked to libharu).
Another guy here on stack overflow has also seen size issues with libharu, but his problem does not mention anything to do with .png so it may be unrelated.
Code for reference:
WorkingGraphic = HPDF_LoadPngImageFromMem ( *gPdfPtr,
PngAssets[AssetIndex], //Image data ptr
PngSizes[AssetIndex]); //data length
//Render Appropriate
HPDF_Page_DrawImage (*BlitParams->page,
WorkingGraphic,
BlitParams->OutputRect->X,
BlitParams->OutputRect->Y,
BlitParams->OutputRect->Width,
BlitParams->OutputRect->Height);
Does anyone know how to drive libharu so it creates sensible sized pdf's when you use .png images?
Right I don't know how to remove a question but maybe this info will be useful to others anyway.
I may have had the same issue as this fellow here where I have duplicated this answer.
What I needed to do was enable compression of the .pdf, which I had not done.
Documentation link
C Code:
HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);
It's because I didn't do enough research to know that .pdf format does not natively support .png, or if it has been updated to do so, libharu still doesn't. So, this option tells libharu to use zlib to zip compress everything it can, including your images.
The implementation is not perfect (you will still see a size difference if you zip your output .pdf) but it is acceptable for my use case.
If you don't need the full-size image in the PDF, you can reduce the image to a thumbnail using GDI+ APIs, equal in size to however big you want the image to appear in the PDF.
Save the scaled PNG to a temporary file, and pass the thumbnail PNG to Haru PDF. This will reduce the size of the PDF file.
The image will be pixellated when the viewer zooms in.
the heading says it all actually:
i want to convert a pdf file into several jpg images. This is to be a part of a software coded in c++ (I'm using Qt for my interface if that matters... :)
Preferably i want the images output to be 72 dpi.
Is there a easy way to do this?
Please comment if you need any more information form me, I'm grateful for any help, tips or answer!
Take pdf2image utility, and run it from you program, collecting its output files.
If you really need single executable (why?) — take a look at its source, and rip everything from it.
You should try to use poppler (or xpdf). You'll have full control of the rendering resolution and can take advantage of image output devices (ImageOutputDev) which will render pages to a framebuffer.Saving this framebuffer to jpeg with libjpeg is ,then , pretty straightforward.
I'm trying to write a JPEG file.
After I acquire the raw image and processing it by DCT, quantization and huffman coding, I would like to save it in the correct format. I couldn't find any libraries that help me to write proper header file, insert the two tables that I used (huffman and quantization), so I started writing everything by myself.
I started with the SOI marker, frame header and so on, but when I try to open the JPEG image with a viewer, it shows nothing, even in the properties. There's no information shown (e.g. the image dimension), even if I insert this info like written in the official documentation.
How can I write a proper JPEG header?
P.S
I use C++ and Visual Studio 2010.
Simple answer - it's complicated.
I would start with libjpeg and use it to just give you the approriate header. You can also use it as a reference for what the internal header structs look like
I am trying to use the ImageNew function (coldfusion 8) to create an image object with a image URL link, e.g. <cfset myImage=ImageNew(evaluate( "http://.../../1.jpg" ))>
There are many links there and most of them are good, but for some of the image links, I got an error when I call the ImageNew function: An exception occurred while trying to read the image. javax.imageio.IIOException: Unsupported Image Type
Does it have something to do with the size of images? Does anybody have any idea?
Many thanks
Results: Finally, it's the CMYK/RGB issue. It seems CF8 has trouble in dealing with CMYK and CF8 doesn't support convertion from CMYK to RGB. I use ImageMagic to do the convertion.
To be fair, I have this issue sometimes. I don't think it has anything to do with your code, coldfusion's image processing utilities either cannot process a perfectly valid image, or they choke on an image that is not up to standards. When this happens it is typically a client uploading an image and my system throws an error. They send me the file, I resave it out using photoshop or something like that, and poof, coldfusion likes it.
The only solution I know if this is the problem, is to use a third party image processor instread of coldfusion's built in functions. I used to use cfx_imagecr
http://efflare.com/products/cfx_imagecr/
But that is not the only solution out there.