OpenCV first program (read image in Xcode)

#include "highgui.h"
int main( int argc, char** argv )
{
   
    IplImage * img = cvLoadImage(argv[ 1 ]); //Note that cvLoadImage() has three parameters
    
    cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE );
    cvShowImage("Example1", img );
    cvWaitKey(0);
    cvReleaseImage( &img );
    cvDestroyWindow("Example1");
    return 0;

 

This is the first routine in the "Learning OpenCV" book, each function has a detailed explanation, I will not repeat it.

 

The problem I encountered is: there is no problem with the code in Xcode, but the picture cannot be displayed. Google for a long time and found that it is the problem of the function cvLoadImage [1] . This function requires two parameters [1] : cvLoadImage(  const  char* filename,  int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR)), please refer to this website for details. Yes, this is the usage of this function. After I understand it, the picture still does not run. Then I found the reason on Google. This is a command line program. After the program is compiled and linked to generate an executable file, it needs to enter the parameters required by the two main functions to the terminal to execute it. One parameter is the executable file generated by the program, and the other is the absolute address of the image. See reference [2] for details

 

What I have to do here is to find the executable files generated by Xcode. Generally, the default executable files of Xcode are uniformly generated under the system folder. I modified the default items in Xcode->Preferences, so that each executable file is generated into the project. folder. Method reference [3]

 

Finally, find the absolute path of the picture. The fastest way is to drag the picture directly into the terminal to see the absolute path of the picture. Then enter in the terminal: the path of the executable file generated by the program in Xcode. Image path. We can output the image we want

 

Quote:

[1] https://blog.csdn.net/hujingshuang/article/details/47184717

[2] https://stackoverflow.com/questions/15356513/opencv-sample-code-run-time-error-using-argv

[3] http://blog.51cto.com/rongbaohong/832335

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324843390&siteId=291194637