tags:

views:

242

answers:

2

Hi Im on mac snow leopard and test these code on xcode3.2 of the Learning OpenCV everything works fine but the image doesnt appear and in the windows. I had try to understand searching for two days what does argv[1] means, but Im still no clear. Im a newbie en C++. I had the image in the same directory where the main.cpp is

#include <OpenCV/cv.h>
#include <OpenCV/highgui.h>



int main(int argc, char** argv)
{
IplImage* interest_img;
CvRect interest_rect;
if( argc == 7 && ((interest_img= cvLoadImage( argv[1],1) ) != 0 ))
{

A more easy example is here:

http://books.google.cl/books?id=seAgiOfu2EIC&amp;pg=PA17&amp;lpg=PA17&amp;dq=cvLoadImage%28argv[1]&amp;source=bl&amp;ots=hRJ5bhkAOf&amp;sig=gyYAqZBnS6lCCXJz9Fz7vzOsF-U&amp;hl=es&amp;ei=dvdvS-fWG8eWtgePy_WCBg&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=6&amp;ved=0CBwQ6AEwBTgK#v=onepage&amp;q=cvLoadImage%28argv[1]&amp;f=false

both I have test it but they dont work. Please help me

A: 

argv[1] is the first command line argument.

It looks like the program is expcing you to supply 6 command line arguments, the first of which is the file name.

You can specify command line arguments in Xcode by doing a "Get Info" on your executable, setting the working directory (set it to Project or Custom, depending on your needs), and then click on the Arguments tab.

Paul R
Dear PaulThanks a lt I dont put all the code of the program but Im trying to load an image see the answer belowI put the image test.jpg inside the my_proyect folder and other one in the my_proyect/build/Debug directory but doesnt workIs there something I made wrong? thanks
ignacionieto
@Ignacio - you didn't say whether you had managed to set up the working directory and command line arguments properly ? The program is expecting 6 command line arguments in total - the first is the program name and the rest appear to be image dimensions, ROI, etc. Without this the code will not run at all.
Paul R
A: 

Dear Paul

Thanks a lt I dont put all the code of the program but Im trying to load an image using

#include "OpenCV/cv.h"
#include "OpenCV/highgui.h"

// ch3_ex3_13 image_name x y width height add# 

int main(int argc, char** argv)
{
    IplImage* interest_img=0;
    CvRect interest_rect;
    if( argc == 7 && ((interest_img=cvLoadImage(argv[1],1)) != 0 ))
    {


  interest_rect.x = atoi(argv[2]);
        interest_rect.y = atoi(argv[3]);
        interest_rect.width = atoi(argv[4]);
        interest_rect.height = atoi(argv[5]);
        int add = atoi(argv[6]);

        // Assuming IplImage *interest_img; and 
        //  CvRect interest_rect;
        //  Use widthStep to get a region of interest
        //
        // (Alternate method)
        //
        IplImage *sub_img = cvCreateImageHeader(
            cvSize(
                interest_rect.width, 
                interest_rect.height
                ),
            interest_img->depth, 
            interest_img->nChannels
            );

        sub_img->origin = interest_img->origin;

        sub_img->widthStep = interest_img->widthStep;

        sub_img->imageData = interest_img->imageData + 
  interest_rect.y * interest_img->widthStep  +
  interest_rect.x * interest_img->nChannels;

        cvAddS( sub_img, cvScalar(add), sub_img );

        cvReleaseImageHeader(&sub_img);

        cvNamedWindow( "Roi_Add", CV_WINDOW_AUTOSIZE );
        cvShowImage( "Roi_Add", interest_img );
        cvWaitKey();
    }
    return 0;
}

I put the image test.jpg inside the my_proyect folder and other one in the my_proyect/build/Debug directory but doesnt work

Is there something I made wrong? thanks

ignacionieto
Dear Ignacio, please write "comments" on answers that others give, or edit your original question, rather than adding your own "answers" which are actually questions. :)
John Zwinck