本文主要是介绍openCV ROI,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/videoio.hpp"
#include <iostream>using namespace std;
using namespace cv;//仅最大化HSV图像S和 V部分
void saturate_sv(IplImage* img)
{for (int y=0; y < img->height; y++){uchar* ptr = (uchar*)(img->imageData + y + img->widthStep);for (int x=0; x < img->width; x++){ptr[3*x+2] = 255;ptr[3*x+3] = 255;}}
}int main(int argc, char **argv)
{IplImage *src;if (argc < 7){std::cout <<"./roi_add <image> x y width height add"<<std::endl;}if( argc == 7 && ((src = cvLoadImage(argv[1], 1)) != 0)){saturate_sv(src);int x = atoi(argv[2]);int y = atoi(argv[3]);int width = atoi(argv[4]);int height = atoi(argv[5]);int add = atoi(argv[6]);cvSetImageROI(src, cvRect(x, y, width, height));cvAddS(src, cvScalar(add), src);cvResetImageROI(src);cvNamedWindow("Roi_Add", 1);cvShowImage("Roi_Add", src);cvWaitKey();}return 0;
}
cmake_minimum_required(VERSION 2.8)project(prydown)find_package(OpenCV REQUIRED)add_executable(pyrdown main.cpp)target_link_libraries(pyrdown ${OpenCV_LIBS})
./roi_add source1.png 150 150 200 200 150
这篇关于openCV ROI的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!