OpenCV 第3天
OpenCV 第3天

OpenCV 第3天

内容纲要

在视频流中使用金字塔降采样

int main(int argc, char** argv){
	namedWindow("Ex1: Customizable pyrDown camera",WINDOW_FULLSCREEN);

	VideoCapture cap;
	cap.open(CAP_DSHOW);

	if(!cap.isOpened()){
		std::cerr << "Could not find camera!" << std::endl;
		return -1;
	}

	int pyrDownRate = 8;
	createTrackbar("pyrDown rate", "Ex1: Customizable pyrDown camera", &g_slider_position, pyrDownRate,onSliderChange);

	std::cout<<3%2<<std::endl;
	Mat img,img_pyr;
	for(;;){
		resizeWindow("Ex1: Customizable pyrDown camera",Size(1920,1080));
		cap >> img;
		cap>>img_pyr;
		int sliderPos = cv::getTrackbarPos("pyrDown rate", "Ex1: Customizable pyrDown camera");
		
		if(sliderPos%2==1)
			++sliderPos;
		for (size_t i = sliderPos; i >=1 ; i/=2)
		{
			pyrDown(img,img,Size((img.cols+1)/2,(img.rows+1)/2));
		}
		imshow("Ex1: Customizable pyrDown camera",img);
		char c = (char)waitKey(32);
		if(c==27)
			break;
		if(c=='i')
			sliderPos+=2;
		if(c=='o')
			sliderPos-=2;
		setTrackbarPos("pyrDown rate", "Ex1: Customizable pyrDown camera",sliderPos);
	}
	return 0;
}

效果则是可以使用滑块来确定降采样的次数。

发表评论

您的电子邮箱地址不会被公开。