opencv图像切割

本文介绍了一个使用OpenCV从立体图像中分离左右视图的示例程序。该程序读取一系列PNG格式的立体图像,将每张图像分割成左图和右图,并显示出来。此外,还演示了如何使用OpenCV函数对图像进行处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include "opencv2/core/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
    Mat src_img, left_img, right_img;
    int frame_id = 0;
    int framenumber = 100;

    int imageHeight;
    int imageWidth;

    while (frame_id < framenumber)
    {
        char filename[100], left_name[100], right_name[100];
        sprintf_s(filename, "E:/stereo_data/ZED/0105/zed-cali_1080/%02d.png", frame_id + 1);  //获取文件名
        cout << "filename is:" << filename << endl;

        src_img = imread(filename);
        if (src_img.empty())
        {
            fprintf(stderr, "Can not load image %s\n", filename);
            return -1;
        }
    
        //非必要i
     mageHeight
= src_img.rows; imageWidth = src_img.cols; printf("imageHeight = %d,imageWidth = %d \n", imageHeight,imageWidth); imshow("src_img", src_img); left_img = src_img(Range(0, 1080), Range(0, 1920)); //Range的两个参数范围为左包含,右不包含,0到1079行、0到1919列的矩形区域 right_img = src_img(Range(0, 1080), Range(1920, 3840)); imshow("left_img", left_img); imshow("right_img", right_img); //sprintf_s(left_name, "left_%02d.png", frame_id); //sprintf_s(right_name, "right_%02d.png", frame_id); imwrite(cv::format("left_name_%02d.png", frame_id), left_img); imwrite(cv::format("right_name_%02d.png", frame_id), right_img); frame_id++; } return 0; }

 

转载于:https://www.cnblogs.com/shaogang/p/6261753.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值