opencv采图时,显示窗口大小如何调整

问题遇到的现象和发生背景

在用C++语言使用OpenCV进行图像采集时,当像素为2560*1440时,显示的的窗口太大了,导致不能看见完整的图像,该怎么把窗口变成正常尺寸?在不放缩的情况下

#include
#include
#include
#include
#include
#include
#include

using namespace std;
using namespace cv;
const char* keys =
{
  "{help h usage ? | | print this message}"
  "{@video | | Video file, if not defined try to use webcamera}"
};
int main(int argc, const char** argv) //程序主函数
{
    CommandLineParser parser(argc, argv, keys);
    parser.about("Video Capture");

    if (parser.has("help")) //帮助信息
    {
        parser.printMessage();
        return 0;
    }
    String videoFile = parser.get<String>(0);
    if (!parser.check())
    {
        parser.printErrors();
        return 0;
    }


    VideoCapture cap0; //定义摄像头对象,准备对每一帧进行处理
    VideoCapture cap1;
    if (videoFile != "")
    {
        cap0.open(videoFile); //打开视频流文件
        cap1.open(videoFile);
    }
    else
    {
        cap0.open(0); //打开相机,电脑自带摄像头一般编号为0,外接摄像头编号为1,主要是在设备管理器中查看自己摄像头的编号。
        cap1.open(1);

        cap0.set(CV_CAP_PROP_FRAME_WIDTH, 2560);  //设置捕获视频的宽度 2560
        cap0.set(CV_CAP_PROP_FRAME_HEIGHT, 1440);  //设置捕获视频的高度 720

        cap1.set(CV_CAP_PROP_FRAME_WIDTH, 2560);  //设置捕获视频的宽度 2560
        cap1.set(CV_CAP_PROP_FRAME_HEIGHT, 1440);  //设置捕获视频的高度 720
    }
    if (!cap0.isOpened()) //判断是否成功打开相机
    {
        cout << "摄像头打开失败!" << endl;
        return -1;
    }

    if (!cap1.isOpened()) //判断是否成功打开相机
    {
        cout << "摄像头打开失败!" << endl;
        return -1;
    }

    Mat frame0, frame1, frame_L, frame_R;
    cap0 >> frame0; //从相机捕获一帧图像
    cap1 >> frame1;
    Mat grayImage; //用于存放灰度数据
   // double fScale = 0.25; //定义缩放系数,对2560*720图像进行缩放显示(2560*720图像过大,液晶屏分辨率较小时,需要缩放才可完整显示在屏幕) 
   // Size dsize0 = Size(frame0.cols * fScale, frame0.rows * fScale);
   /// Size dsize1 = Size(frame1.cols * fScale, frame1.rows * fScale);

    Mat imagedst0;
    Mat imagedst1;

  //  resize(frame0, imagedst0, dsize0);
  //  resize(frame1, imagedst1, dsize1);

    char key;
    char image_left[200];
    char image_right[200];
    int count1 = 0;
    int count2 = 0;
    namedWindow("图片1", 1);
    namedWindow("图片2", 1);
    while (1)
    {
        key = waitKey(50);
        cap0 >> frame0; //从相机捕获一帧图像
        cap1 >> frame1;
       // resize(frame0, imagedst0, dsize0); //对捕捉的图像进行缩放操作
      //  resize(frame1, imagedst1, dsize1);

        frame_L = frame0;  //获取缩放后左Camera的图像 640*360
        namedWindow("Video_L", 1);
        imshow("Video_L", frame_L); //显示左摄像头拍摄的图像

        frame_R = frame1; //获取缩放后右Camera的图像
        namedWindow("Video_R", 2);
        imshow("Video_R", frame_R);
        if (key == 27) //按下ESC退出
            break;
        if (key == 32) // 按下空格开始拍照图片保存在工程文件下
        {
            sprintf_s(image_left, "l%d.bmp", ++count1);
            imwrite(image_left, frame_L);

            imshow("图片1", frame_L);
            sprintf_s(image_right, "r%d.bmp", ++count2);
            imwrite(image_right, frame_R);
            imshow("图片2", frame_R);
        }
    }
    return 0;
}

https://www.csdn.net/tags/Mtjacg1sODA3NjItYmxvZwO0O0OO0O0O.html
你看看这个博客有没有帮助?

img


python中使用这个函数,C语言应该差不多,应该会对你有帮助

img


或者尝试等比例缩放,试试看,让他处于你设置的

img


再来的小一点,在自己电脑看的也舒服!

可以看看摄像头支持什么样子的,直接resiz成那个