OpenCV-C++——基本操作总结

基本图像操作

获取图像尺寸

cv::Mat image;
image.rows // 宽 480 int
image.cols // 长 640 int

图像镜像

  • 使用flip函数实现镜像:
//上下左右镜像    
Mat dst;
cv::flip(src, dst, -1);
 
//上下镜像
Mat dst;
cv::flip(src, dst, 0);
 
//左右镜像
Mat dst;
cv::flip(src, dst, 1);
  • 旋转操作,使用转置+镜像配合完成:transpose + flip
//顺时针旋转90度
Mat dst, tempPic;
cv::transpose(src, tempPic);
cv::flip(tempPic, dst, 1);
 
//逆时针旋转90度
Mat dst, tempPic;
cv::transpose(src, tempPic);
cv::flip(tempPic, dst, 0);
 
//顺时针旋转180度=上下镜像+左右镜像
Mat dst;
cv::flip(src, dst, -1);

遍历图像

int scan_image_random(Mat &I)
{
    
    
    for( int i = 0; i < I.rows; ++i)
    {
    
    
        for( int j = 0; j < I.cols; ++j 
        {
    
    
            I.at<Vec3b>(i, j)[0] = 0;
            I.at<Vec3b>(i, j)[1] = 0;
            I.at<Vec3b>(i, j)[2] = 0;
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_45779334/article/details/124331982