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;
    }
  • 相关阅读:
    。net文件缓存 枫
    C#实现冒泡排序 堆栈 队列 枫
    Android程序开发初级教程(三) 枫
    c#语法片段总结 枫
    Eclipse快捷键大全(转载) 枫
    asp.net页面缓存技术(Cache、XML) 枫
    android案例 枫
    DIV CSS兼容性解决IE6/IE7/FF浏览器的通用方法完美兼容 枫
    List<>.Contains<>的用法 枫
    sql 获取表结构信息(2005) 枫
  • 原文地址:https://www.cnblogs.com/chenyang920/p/5345679.html
Copyright © 2011-2022 走看看