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;
    }
  • 相关阅读:
    POJ 3468 区间更新,区间求和(经典)
    HDU 1698 区间更新
    POJ 2828 单点更新(好题)
    HDU 2795 单点更新,区间优先查找(想法)
    HDU 1394 树状数组求逆序对
    HDU 1754 单点更新,求区间最大值
    Servlet 3.0 对异步处理的支持
    Servet3.0于Servlet2.5比较
    你的灯还亮着吗读书笔记3
    你的灯还亮着吗读书笔记2
  • 原文地址:https://www.cnblogs.com/chenyang920/p/5345679.html
Copyright © 2011-2022 走看看