zoukankan      html  css  js  c++  java
  • 用imageROI来增加某范围的像素

    #include <cv.h>
    #include <highgui.h>
    int main(int argc, char** argv)
    {
        IplImage* src;
        if (((src = cvLoadImage("001.jpg", 1)) != 0))
        {
            int x = 1000;
            int y = 400;
            int width = 400;
            int height = 400;
            int add = 50;
            //给定图片的从左上角(x,y) 长宽为width,height的区域进行ROI增加像素
            cvSetImageROI(src, cvRect(x, y, width, height));
            //增加像素 并且存储在src
            cvAddS(src, cvScalar(add), src);
            //释放基于给定矩形的ROI
            cvResetImageROI(src);
            //创建窗口
            cvNamedWindow("Src", 1);
            //通过新建的窗口对src进行show
            cvShowImage("Src", src);
            cvWaitKey();
        }
        return 0;
    }
    #include <cv.h>
    #include <highgui.h>
    int main(int argc, char* argv[])
    {
        IplImage* interest_img = cvLoadImage("001.jpg");
        // 确定一个矩形区域  参数分别是左/右上角坐标 具体根据截取原图的 origin
        CvRect      interest_rect = cvRect(400, 400, 400, 400);
        //创建一个图像的头  具体为截取的图片
        IplImage *sub_img = cvCreateImageHeader(cvSize(interest_rect.width, interest_rect.height), interest_img->depth, interest_img->nChannels);
        // 截取图形的原点 根据原图获得
        sub_img->origin = interest_img->origin;
        //校队后的行字节数
        sub_img->widthStep = interest_img->widthStep;
        //图像数据的指针
        sub_img->imageData = interest_img->imageData + interest_rect.y * interest_img->width + interest_rect.x * interest_img->nChannels;
        //为截取的图像增加像素
        cvAddS(sub_img, cvScalar(50), sub_img);
        cvNamedWindow("main");
        cvNamedWindow("result");
        //通过窗口展示原图像和截取图像
        cvShowImage("main", interest_img);
        cvShowImage("result", sub_img);
        cvWaitKey();
        //释放内存
        cvReleaseImage(&interest_img);
        cvReleaseImageHeader(&sub_img);
        cvDestroyWindow("main");
        cvDestroyWindow("result");
        return 0;
    }
  • 相关阅读:
    可持久化线段树区间查询 + 永久化标记 T^T online judge 2507
    可持久化线段树
    T^T online judge 3441
    食物链
    T^T ONLINE JUDGE 2592
    HDU 6312 GAME
    HDU 1430 魔板
    栈的操作链表+数组版
    Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round) D. Peculiar apple-tree
    Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round) C. Laboratory Work
  • 原文地址:https://www.cnblogs.com/chenyang920/p/5345679.html
Copyright © 2011-2022 走看看