• 用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;
    }
  • 相关阅读:
    多线程按序打印1-100
    负载均衡算法
    day05_05 for循环、break语句
    day05_04 数据类型-数值、布尔值、字符串简介
    day05_03 字符串格式化
    day05_02 IDE介绍及设置
    小甲鱼零基础入门PYTHON
    day01_14.遍历数组
    day01_13.数组
    day01_11.break和continue
  • 原文地址:https://www.cnblogs.com/chenyang920/p/5345679.html
Copyright © 2020-2023  润新知