What does the command String imageName( "../data/HappyFish.jpg" ); do? - opencv

I am a total beginner in OpenCV. I was learning a program to load and display an image where the below statement is used.
String imageName( "../data/HappyFish.jpg" ); //by default
what does this statement do?

This statement is the folder directory of the image file HappyFish.jpg in the OpenCV example Load and Display an Image. Simply it is used with imread to indicate the location where our image file is located.
image = imread( imageName, IMREAD_COLOR ); // Read the file

Related

jpg images without extension aren't displayed

from kivy.uix.image import Image
self.img = Image(source="image") # This works when image is an PNG image
self.img = Image(source="image.jpg") # This works when image.jpg is a JPG image
self.img = Image(source="image") # This doesn't work when image is a JPG image
I need to specify images without extention for the app to be generic (working with more image types). Can I achieve it somehow?
Kivy is using "imghdr" to determine the image type here, and as a fallback it uses the file extension here.
That explains why the image loads fine when it has a file extension, even though "imghdr" can't find the file type in the file's content.
I tested on a list of JPEG files, and each time "imghdr" was able to detect the file type each time. That is done here im imghdr. Notably, "imghdr" does not consider the file extension.
$ python
>>> import os, imghdr
... for f in os.listdir('.'):
... print('%s -- %s' % (f, imghdr.what(f)))
Maybe the JPEG file is missing the "JFIF" or "Exif" string that imghdr is looking for? You could use hexedit to see if one of those string is present at Byte 6 of the image file.

How to convert Unit8List to Files in flutter

I have used opencv to enhance the image in flutter which returns a Unit8List as a dynamic result i have used to display the image.
Image newImage = Image.memory(res);
How to convert that image it to file, or how to write Unit8List as a file. I have tried this but its printing ���� as the file path
File imageNeww = File.fromRawPath(res);
print(imageNeww.path);
Use the file class
File f = File('desired/path/to/file.png');
await f.writeAsBytes(bytes);
here bytes are your Uint8List

Batch save all opened files in GIMP .xcf

I have a series of manually edited images and layers in GIMP, each set is in a single tab. All want to save all of them into different .xcf's.
I am aware of some scripts to export them as images (like this one), but I want to save them as .xcf, not export the images. Moreover, I would like to have them in a single folder, so that I can load them all in the future.
Is there any script to do this?
You can save all projects using this code bellow
dirname = “Path of file”
path = “File name”
imgs = gimp.image_list();
num = 0;
for img in imgs:
for layer in img.layers:
fullpath = os.path.join(path, dirname+str(num)+'.xcf');
pdb.gimp_xcf_save(0, img, layer, fullpath, fullpath);
num += 1;
Or, if you can install complete plugin in https://github.com/Tushn/GIMP-Plugins/blob/master/src/saveproject.py
Instructions for install in https://github.com/Tushn/GIMP-Plugins
If you want open all file, so it’s enough that you mark all xcf in directory and enter in GIMP (click right buttom mouse, case your GIMP is not default file).

using imread of OpenCV failed when the image is Ok

I encountered a problem when I want to read an image using the OpenCV function imread().
The image is Ok and I can show it in the image display software.
But when I use the imdecode() to get the image data, the data returns NULL.
I will upload the image and the code and hope some one could help me
Mat img = imread(image_name);
if(!img.data) return -1;
The image's link is here: http://img3.douban.com/view/photo/raw/public/p2198361185.jpg
PS: The image_name is all right.
I guess OpenCV cannot decode this image. So is there any way to decode this image using OpenCV?, like add new decode library. By the way, I can read this image using other image library such as freeImage.
Your image is in .gif and it is not supported by OpenCV as of now.
Note OpenCV offers support for the image formats Windows bitmap (bmp),
portable image formats (pbm, pgm, ppm) and Sun raster (sr, ras). With
help of plugins (you need to specify to use them if you build yourself
the library, nevertheless in the packages we ship present by default)
you may also load image formats like JPEG (jpeg, jpg, jpe), JPEG 2000
(jp2 - codenamed in the CMake as Jasper), TIFF files (tiff, tif) and
portable network graphics (png). Furthermore, OpenEXR is also a
possibility.
Source - Click here
You can use something like this, to perform the conversion.
I was able to load your image using imread using this. Also, you can check out FreeImage.
You can also try to use the library gif2numpy. It converts a gif image to a numpy image which then can be loaded by OpenCV:
import cv2, gif2numpy
np_images, extensions, image_specs = gif2numpy.convert("yourgifimage.gif")
cv2.imshow("np_image", np_images[0])
cv2.waitKey()
The library can be found here: https://github.com/bunkahle/gif2numpy It is not dependent on PIL or pillow for this like imageio.
There are two methods to read an image in OpenCV, one is using Mat the other one using IplImage. I see you have used the former one. You can try with the second argument of imread also:
image = imread("image.jpg", CV_LOAD_IMAGE_COLOR); // Read the file
else use IplImage
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include <opencv2/core/core.hpp>
IplImage* src = 0;
if( (src = cvLoadImage("filename.jpg",1)) == 0 )
{
printf("Cannot load file image %s\n", filename);
}
If they don't work please check if you have installed libjpeg, libtiff and other dependencies for reading an image in OpenCV.
Hope it would help.

loading image in opencv2.4.6

In opencv 2.4.6. I am trying to load a mat image file with a simple code given below. But the image is not loaded as I print the image size, it is showing '0'. Can anybody please tell me , what is going wrong?
int main(int argc, char argv[])
{
Mat a=imread("C:/image3.jpg");
cv::Size frame11_size = a.size();
printf("%d",frame11_size.height);
return 0;
}
Update: I solved the problem. The problem was, I was only including all the library,include and additional dependencies in 'debug mode' only. I did not change anything in 'release mode'. When I change the properties in 'release mode' as-well, it worked. thanks all for your kind responses, I am giving '+1' for your answers.
I think there should be single slash on your image path, and always check whether image is successfully loaded.
Mat a=imread("C:/image3.jpg");
if(! a.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
OpenCV can't open jpg files by itself. It depends on third parties to do so. Maybe you are missing certain dlls, or maybe your OpenCV installation don't have the right path to them. To test this assumption store your image in other formats. For example pgm or ppm. Those formats does not perform any encoding and just store image buffer in file as is. As a result OpenCV will not need any external libraries to open image in ppm format.

Resources