Raspberry pi-OpenCV Modify image tutorial - Raspberry Pi Forums
hello,
trying tutorial learn how pass arguments inside code, supposed convert existing image grayscale , save it. here link: http://docs.opencv.org/2.4/doc/tutorial ... save-image
here code (i compiled same thing):
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main( int argc, char** argv )
{
char* imagename = argv[1];
mat image;
image = imread( imagename, 1 );
if( argc != 2 || !image.data )
{
printf( " no image data \n " );
return -1;
}
mat gray_image;
cvtcolor( image, gray_image, cv_bgr2gray );
imwrite( "../../images/gray_image.jpg", gray_image );
namedwindow( imagename, cv_window_autosize );
namedwindow( "gray image", cv_window_autosize );
imshow( imagename, image );
imshow( "gray image", gray_image );
waitkey(0);
return 0;
}
error:
terminate called after throwing instance of 'std::logic_error"
(): basic_string::_s_contruct not null valid
aborted
searched error , people suggest checking argc (int) number before starting code. checked it, argc 1. supposed 2 call argv[1]. how can handle situation? need convert existing image grayscale , save it.
trying tutorial learn how pass arguments inside code, supposed convert existing image grayscale , save it. here link: http://docs.opencv.org/2.4/doc/tutorial ... save-image
here code (i compiled same thing):
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main( int argc, char** argv )
{
char* imagename = argv[1];
mat image;
image = imread( imagename, 1 );
if( argc != 2 || !image.data )
{
printf( " no image data \n " );
return -1;
}
mat gray_image;
cvtcolor( image, gray_image, cv_bgr2gray );
imwrite( "../../images/gray_image.jpg", gray_image );
namedwindow( imagename, cv_window_autosize );
namedwindow( "gray image", cv_window_autosize );
imshow( imagename, image );
imshow( "gray image", gray_image );
waitkey(0);
return 0;
}
error:
terminate called after throwing instance of 'std::logic_error"
(): basic_string::_s_contruct not null valid
aborted
searched error , people suggest checking argc (int) number before starting code. checked it, argc 1. supposed 2 call argv[1]. how can handle situation? need convert existing image grayscale , save it.
yes, badly written program. code should check argc 2, before using argv[1]. however, guessing comment aren't passing name of image file program on command line.
need run program follows
filename.jpg existing image file. if file isn't in current directory need provide path file. also, replace a.out name of executable creating.
code have been better written as:-
need run program follows
code: select all
./a.out filename.jpg
code have been better written as:-
code: select all
#include <cv.h> #include <highgui.h> using namespace cv; int main( int argc, char** argv ) { if( argc != 2 || !image.data ) { printf( "usage %s input.jpg\n ", argv[0] ); return -1; } char* imagename = argv[1]; mat image; image = imread( imagename, 1 ); mat gray_image; cvtcolor( image, gray_image, cv_bgr2gray ); imwrite( "gray_image.jpg", gray_image ); namedwindow( imagename, cv_window_autosize ); namedwindow( "gray image", cv_window_autosize ); imshow( imagename, image ); imshow( "gray image", gray_image ); waitkey(0); return 0; }
raspberrypi
Comments
Post a Comment