Ask Your Question

why I am not getting Image??

asked 2015-06-01 03:11:21 -0500

Akki gravatar image

updated 2015-06-01 03:16:23 -0500

berak gravatar image

I am trying to load image, but I always get blank window frame.

this is the header file,

#pragma once

class project

bool image( char* imgName);


this is .cpp file

#include "project.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"

using namespace cv;



bool project::image(char* imgName)

    Mat imgOriginal = imread(imgName);

    imshow("original", imgOriginal);
    return 0;


this is the main.cpp file

#include "project.h"
#include <iostream>
#include <string> 

using namespace std;

int main()
       project ob1;



can someone please guide me where I am getting error. Thank you very much in advance.

edit retag flag offensive close merge delete



you need a call to cv::waitKey(someMillis); after each call to imshow() , else your window will never get updated. (you also should skip the getchar(); here.

berak gravatar imageberak ( 2015-06-01 03:17:35 -0500 )edit

Thank you very much. Its work fine.

Akki gravatar imageAkki ( 2015-06-01 04:07:36 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-06-01 04:16:40 -0500

Lahcene gravatar image

updated 2015-06-01 07:32:28 -0500

thdrksdfthmn gravatar image

Hello, Your image is on 32-bit while the imshow is working on 8-bits. so you should use

Mat imgOriginal = imread(imgName,0); //instead of Mat imgOriginal = imread(imgName);

you need also to add cv::waitKey(0); always after calling imshow for having the time to see the image.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-06-01 03:11:21 -0500

Seen: 119 times

Last updated: Jun 01 '15