Ask Your Question
0

why I am not getting Image??

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

Akki gravatar image

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

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
{
public:
    project(void);
    ~project(void);



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;


project::project(void)
{
}


project::~project(void)
{
}

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;
       ob1.image("2.JPG");

       getchar();

}

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

edit retag flag offensive close merge delete

Comments

1

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 -0600 )edit

Thank you very much. Its work fine.

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

1 answer

Sort by ยป oldest newest most voted
1

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

Lahcene gravatar image

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

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

Stats

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

Seen: 198 times

Last updated: Jun 01 '15