zoukankan      html  css  js  c++  java
  • 学习Opencv Chat3

    • 基础结构体

    CvPoint int x,y

    CvPoint2D32f Float x,y;

    CvSize Int width,height

    CvRect int x,y,width,height

    CvScalar double val[4] 这里为RGBA的值

    • CvMat
    typedef struct CvMat {
        int type;
        int step;
        int* refcount;     // for internal use only
        union {
             uchar* ptr;
             short* s;
             int*    i;
             float* fl;
             double* db;
        } data;
        union {
             int rows;
             int height;
        };
        union {
             int cols;
             int width;
        };
    } CvMat;
    float vals[] = [1,2,3,4];
    cvCreateMat(5,5, CV_32FC1);
    CvInitMatHeader {
        &Mat, 2, 2, CV_32FC1, vals  
    }
    *( (float*)CV_MAT_ELEM_PTR(*mat, 3, 2) ) = 7.7; // 赋值
    cvmSet(mat, 2, 2, 0.5); 
    double cvGet(mat, 2,2);
    • IplImage
    // 对于指定区域进行色彩加强
    int main(){
        char input[] = "/Users/basasuya/Downloads/1.jpg";
        IplImage* src = cvLoadImage(input);
        int x,y,width,height,add;
        scanf("%d %d %d %d %d",&x,&y,&width,&height,&add);
        cvSetImageROI(src, cvRect(x,y,width,height));
        cvAddS(src, cvScalar(add), src);
        cvResetImageROI(src);
        cvNamedWindow("Roi_Add", 1);
        cvShowImage("Roi_Add", src);
        cvWaitKey();
    }
    //另一种加强的方式
    int main(){
        char input[] = "/Users/basasuya/Downloads/1.jpg";
        IplImage* src = cvLoadImage(input);
        int x,y,width,height,add;
        scanf("%d %d %d %d %d",&x,&y,&width,&height,&add);
      //  cvSetImageROI(src, cvRect(x,y,width,height));
        IplImage* cha = cvCreateImageHeader(cvSize(width, height), src->depth, src->nChannels);
        cha->origin = src->origin;
        cha->widthStep = src->widthStep;
        cha->imageData = src->imageData + y* src->widthStep + x* src->nChannels;
        cvAddS(cha, cvScalar(add), cha);
        cvReleaseImageHeader(&cha);
        cvNamedWindow("Roi_add", CV_WINDOW_AUTOSIZE);
        cvShowImage("Roi_add", src);
        cvWaitKey();
        return 0;
    }
    
    //将两个图片进行叠加
    int main(){
        char input1[] = "/Users/basasuya/Downloads/1.jpg";
        char input2[] = "/Users/basasuya/Downloads/2.jpg";
    
        IplImage* s1 = cvLoadImage(input1);
        IplImage* s2 = cvLoadImage(input2);
        int x,y,width,height;
        double alpha, beta;
        scanf("%d %d %lf %lf",&x,&y,&alpha,&beta);
        width = s2->width; height = s2->height;
      //  cvSetImageROI(src, cvRect(x,y,width,height));
        cvSetImageROI(s1, cvRect(x,y,width,height));
        cvSetImageROI(s2, cvRect(0,0,width,height));
        cvAddWeighted(s1, alpha, s2, beta, 0, s1);
        cvResetImageROI(s1);
        ShowImg(s1);
        return 0;
    }
  • 相关阅读:
    JAVA学习日记1-0706
    同步一个fork
    面试题 17.13. 恢复空格-7月9日
    3. 无重复字符的最长子串(leetcode)-7月8日
    面试题 16.11. 跳水板(leetcode)-7月8日
    112.路径总和(leetcode)-7月7日
    Git使用入门
    第一次尝试
    OpenPCDet: Open-MMLab 面向LiDAR点云表征的3D目标检测代码库
    人工智能和机器学习能为抗击新冠肺炎做些什么?
  • 原文地址:https://www.cnblogs.com/Basasuya/p/8433717.html
Copyright © 2011-2022 走看看