Retinex实例

Retinex实例

1、代码:

#include <iostream>
#include <cstring>

#include "opencv2/opencv.hpp"

using namespace cv;

static void help(std::string errorMessage)
{
	std::cout<<"Program init error : "<<errorMessage<<std::endl;
	std::cout<<"\nProgram call procedure : retinaDemo [processing mode] [Optional : media target] [Optional LAST parameter: \"log\" to activate retina log sampling]"<<std::endl;
	std::cout<<"\t[processing mode] :"<<std::endl;
	std::cout<<"\t -image : for still image processing"<<std::endl;
	std::cout<<"\t -video : for video stream processing"<<std::endl;
	std::cout<<"\t[Optional : media target] :"<<std::endl;
	std::cout<<"\t if processing an image or video file, then, specify the path and filename of the target to process"<<std::endl;
	std::cout<<"\t leave empty if processing video stream coming from a connected video device"<<std::endl;
	std::cout<<"\t[Optional : activate retina log sampling] : an optional last parameter can be specified for retina spatial log sampling"<<std::endl;
	std::cout<<"\t set \"log\" without quotes to activate this sampling, output frame size will be divided by 4"<<std::endl;
	std::cout<<"\nExamples:"<<std::endl;
	std::cout<<"\t-Image processing : ./retinaDemo -image lena.jpg"<<std::endl;
	std::cout<<"\t-Image processing with log sampling : ./retinaDemo -image lena.jpg log"<<std::endl;
	std::cout<<"\t-Video processing : ./retinaDemo -video myMovie.mp4"<<std::endl;
	std::cout<<"\t-Live video processing : ./retinaDemo -video"<<std::endl;
	std::cout<<"\nPlease start again with new parameters"<<std::endl;
	std::cout<<"****************************************************"<<std::endl;
	std::cout<<" NOTE : this program generates the default retina parameters file 'RetinaDefaultParameters.xml'"<<std::endl;
	std::cout<<" => you can use this to fine tune parameters and load them if you save to file 'RetinaSpecificParameters.xml'"<<std::endl;
}

int main(int argc, char* argv[]) 
{
	bool useLogSampling = false; // "log" // check if user wants retina log sampling processing
	std::string inputMediaType="-image"; // argv[1],如果为“-video”且useLogSampling = false则从摄像头读取视频
	string imageOrVideoName = "noise image.jpg"; // argv[2]--lena.jpg



	// declare the retina input buffer... that will be fed differently in regard of the input media
	Mat inputFrame, image;
	VideoCapture videoCapture; // in case a video media is used, its manager is declared here

	if (!strcmp(inputMediaType.c_str(), "-image") )		//处理图像
	{
		std::cout<<"RetinaDemo: processing image "<<imageOrVideoName<<std::endl;
		inputFrame = imread(imageOrVideoName, 0); // load image in RGB mode
	}
	else	//处理视频
	{
		if (!strcmp(inputMediaType.c_str(), "-video"))
		{
			if (useLogSampling) // attempt to grab images from a video capture device
			{
				videoCapture.open(0);
			}
			else// attempt to grab images from a video filestream
			{
				std::cout<<"RetinaDemo: processing video stream "<<imageOrVideoName<<std::endl;
				videoCapture.open(imageOrVideoName);
			}
			// grab a first frame to check if everything is ok
			videoCapture>>inputFrame;
		}
		else
		{
			help("bad command parameter");
			return -1;
		}
	}
	if (inputFrame.empty())	
	{
		help("Input media could not be loaded, aborting");
		return -1;
	}

	try
	{
		// create a retina instance with default parameters setup, uncomment the initialisation you wanna test
		Ptr<Retina> myRetina;

		// if the last parameter is 'log', then activate log sampling (favour foveal vision and subsamples peripheral vision)
		if (useLogSampling)
		{
			myRetina = new cv::Retina(inputFrame.size(), true, cv::RETINA_COLOR_BAYER, true, 2.0, 10.0);
		}
		else// -> else allocate "classical" retina :
			myRetina = new cv::Retina(inputFrame.size());
		//               myRetina = &inputFrame.clone();

		// save default retina parameters file in order to let you see this and maybe modify it and reload using method "setup"
		myRetina->write("RetinaDefaultParameters.xml");

		// load parameters if file exists
		//        myRetina->setup("RetinaSpecificParameters.xml");
		myRetina->setup("RetinaDefaultParameters.xml");

		//        // reset all retina buffers (imagine you close your eyes for a long time)
		myRetina->clearBuffers();

		// declare retina output buffers
		cv::Mat retinaOutput_parvo;
		cv::Mat retinaOutput_magno;

		// processing loop with no stop condition
		for(;;)
		{
			// if using video stream, then, grabbing a new frame, else, input remains the same
			if (videoCapture.isOpened())
				videoCapture>>inputFrame;

			// run retina filter on the loaded input frame
			myRetina->run(inputFrame);

			// Retrieve and display retina output
			myRetina->getParvo(retinaOutput_parvo);
			myRetina->getMagno(retinaOutput_magno);
			cv::imshow("retina input", inputFrame);
			cv::imshow("Retina Parvo", retinaOutput_parvo);
			cv::imshow("Retina Magno", retinaOutput_magno);
			cv::waitKey(10);
		}
	}
	catch(cv::Exception e)
	{
		std::cerr<<"Error using Retina : "<<e.what()<<std::endl;
	}

	// Program end message
	std::cout<<"Retina demo end"<<std::endl;

	return 0;
}

2、运行结果


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值