Ask Your Question
0

where should I put my image ?

asked 2013-06-01 12:11:15 -0600

colin gravatar image

updated 2013-06-01 13:06:52 -0600

Guanta gravatar image

Here is the code to show the image :

#include "highgui.h"
#include <iostream>
#include <cv.h>

using namespace std;

int main(int argc,char** argv)
{
    char filename[]="0.jpg";
    IplImage* img = cvLoadImage(filename,CV_LOAD_IMAGE_UNCHANGED);
    if(!img){
      cout<<"Error: Couldn't open the image file.\n";
    }
    cvNamedWindow("Example1",CV_WINDOW_AUTOSIZE);
    cvShowImage("Example1",img);
    cvvWaitKey(0);
    cvReleaseImage(&img);
    cvDestroyWindow("Example1");
}


>>> char filename[]="0.jpg";

How can it load an image without telling it the direct path of the image? or should I put my image in a default path?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-06-01 12:38:04 -0600

Jawaher Khemakhem gravatar image

updated 2013-06-01 12:40:16 -0600

There is two methods for calling a file :

  • absolute path

C:\projects\myProject\img.png

  • non absolute path (relative path)

img.png

Do not forget to put the path between " " .

In the above example, the absolute path contains the full path to the file and not just the file as seen in the non absolute path.

For example , you can put your code source test.cpp and your image in a folder ,name it for example opencv and try the non absolute path .

edit flag offensive delete link more

Comments

I'm still confusing ~ if I want to show an image under the path "C:\Users\colin\Desktop\pictures\0.jpg" how should i modify my code?

colin gravatar imagecolin ( 2013-06-01 19:17:05 -0600 )edit

You can create a folder "projectsOpencv " in your desktop , put the file containing your code "example.cpp" and your image "0.jpg"in the same folder "projectsOpencv" . In this case , char filename[]="0.jpg"; do not modify your code .

Jawaher Khemakhem gravatar imageJawaher Khemakhem ( 2013-06-02 02:27:50 -0600 )edit

Question Tools

Stats

Asked: 2013-06-01 12:11:15 -0600

Seen: 433 times

Last updated: Jun 01 '13