Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imshow function in openCV

Tags:

c++

opencv

I am using imshow function to display images in OpenCV. It works fine, there is just a little thing though: the title I write for the image is not correctly displayed.

For example, when I write "Original" or "inverted" they are displayed with some extra and unintelligible data in the beginning. However, when I write "thresholded Image" a long line of unintelligible words is displayed instead of the title...

It does not effect anything else but it seems queer to me. Do you have any idea why that happens?

Here is my code:

IplImage* image=cvLoadImage("Black&White.jpg");
Mat image1;
image1=Mat(image,false);
imshow("Image",image1);
cvWaitKey(0);
like image 205
Aayman Khalid Avatar asked Mar 18 '13 09:03

Aayman Khalid


People also ask

What is Imshow in OpenCV?

imshow() method is used to display an image in a window. The window automatically fits to the image size. Syntax: cv2.imshow(window_name, image) Parameters: window_name: A string representing the name of the window in which image to be displayed.

What is Imshow used for?

Description. imshow( I ) displays the grayscale image I in a figure. imshow uses the default display range for the image data type and optimizes figure, axes, and image object properties for image display.

How does cv2 Imshow work?

Working of imshow() function in OpenCVThe imshow() function takes two parameters namely window_name and image. The parameter window_name is the name of the window within which the given image must be displayed. The parameter image is the image to be displayed in a window.

What is Imshow in Python?

The matplotlib function imshow() creates an image from a 2-dimensional numpy array. The image will have one square for each element of the array. The color of each square is determined by the value of the corresponding array element and the color map used by imshow() .


1 Answers

First of all, you are using the C and C++ libraries interchangeably - IpIImage belongs to C and Mat belongs to C++, this could be the source of your problem. Instead, try just using the C++ interface and your code will be as follows :

Mat image = imread("Black&White.jpg"); 
imshow("Image",image);
waitKey(0);

That should fix your problem, if not, try using the C interface

IplImage* image = cvLoadImage("Black&White.jpg");
cvNamedWindow( "Image", CV_WINDOW_AUTOSIZE );
cvShowImage("Image", image);
cvWaitKey(0);
like image 96
MattTheHack Avatar answered Oct 02 '22 17:10

MattTheHack