【学习opencv 一】opencv3/C++实现图像的读入显示和写出

【学习opencv 一】opencv3/C++实现图像的读入显示和写出

方法1:

//Example 1. A simple OpenCV program that loads an image from disk and displays it
//on the screen
#include 

void help(char** argv ) {
	std::cout << "\n"
	<< "A simple OpenCV program that loads and displays an image from disk\n"
	<< argv[0] <<" \n"
	<< "For example:\n"
	<< argv[0] << " ../fruits.jpg\n"
	<< std::endl;
}
	

int main( int argc, char** argv ) {
	
	if (argc != 2) {
		help(argv);
		return 0;
	}
		

  cv::Mat img = cv::imread( argv[1], -1 );

  if( img.empty() ) return -1;

  cv::namedWindow( "Example 2-1", cv::WINDOW_AUTOSIZE );
  cv::imshow( "Example 2-1", img );
  cv::waitKey( 0 );
  cv::destroyWindow( "Example 2-1" );

  return 0;
}

方法2:

//Example 1. A simple OpenCV program that loads an image from disk and displays it
//on the screen
#include 

using namespace cv;
using namespace std;

void help(char** argv ) {
	cout << "\n"
	<< "A simple OpenCV program that loads and displays an image from disk\n"
	<< argv[0] <<" \n"
	<< "For example:\n"
	<< argv[0] << " ../fruits.jpg\n"
	<< endl;
}
	

int main( int argc, char** argv ) {
	
	if (argc != 2) {
		help(argv);
		return 0;
	}
		

  Mat img = imread( argv[1], -1 );

  if( img.empty() ) return -1;

  namedWindow( "Example 1", WINDOW_AUTOSIZE );
  imshow( "Example 1", img );
  waitKey( 0 );
  destroyWindow( "Example 1" );

  return 0;
}

实验原图:
【学习opencv 一】opencv3/C++实现图像的读入显示和写出_第1张图片
结果:
【学习opencv 一】opencv3/C++实现图像的读入显示和写出_第2张图片
欢迎关注微信公众号:FPGA开源工作室
获取更多学习资料。
FPGA开源工作室

你可能感兴趣的:(opencv,opencv数字图像处理)