Question

In the code below,'reader->SetFileName()' has an image input into it as 'argv[1]'. My question may seem...

In the code below,'reader->SetFileName()' has an image input into it as 'argv[1]'.
My question may seem stupid, but how do i get my image file stored into that argv array?





#include "itkImageFileReader.h"

int
main(int argc, char * argv[])
{
  if (argc != 2)
  {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0];
    std::cerr << " <InputFileName>";
    std::cerr << std::endl;
    return EXIT_FAILURE;
  }

  constexpr unsigned int Dimension = 2;

  using PixelType = unsigned char;
  using ImageType = itk::Image<PixelType, Dimension>;

  using ReaderType = itk::ImageFileReader<ImageType>;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(argv[1]);
  reader->Update();

  ImageType::Pointer image = reader->GetOutput();

  return EXIT_SUCCESS;
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

In case of any query do comment.

Answer: You don't need to store image file into argv array. argv array is used for taking command line input in your program. so you have to pass name of the image file as input file name which will be read into arg array by the compiler. so if you see your program, you are checking for argc , if it is not 2 you are showing error to the user as below:

and argv is an array command. When you run your c++ program from command line after compiling, you simply run /.a.out (which is output of the compiler) or you compile as below:

g++ main.cpp -o main.exe where output is main.exe

then run the program as below:

main.exe "c"\a.jpg"

above line will store argc =2 and argv [0] as main.exe and argv[1] would be "c:\a.jpg" which you are actually passing into reader->SetFileName(argv[1]);

Add a comment
Know the answer?
Add Answer to:
In the code below,'reader->SetFileName()' has an image input into it as 'argv[1]'. My question may seem...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT