调用双目相机(C++、Python)

本文介绍了如何使用C++和Python将双目相机拍摄的照片分开为左右两张图片,分别提供了C++版和Python版的实现方法。

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

将双目相机拍照并且分为左右两张图片

1、C++版

#include "opencv2/opencv.hpp"
#include <string>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
	VideoCapture inputVideo(1);//0-笔记本自带摄像头,1-外接usb双目摄像头

	if (!inputVideo.isOpened())
	{
		cout << "Could not open the input video " << endl;
		return -1;
	}

	Mat frame, Left, Right;
	string leftname,rightname;

	int f = 1;
	while (1) //Show the image captured in the window and repeat
	{
		inputVideo >> frame;              // read
		if (frame.empty()) break;         // check if at end
		
		Left  = frame(Rect(0, 0, frame.size().width / 2, frame.size().height));						//分割图片
		Right = frame(Rect(frame.size().width / 2, 0, frame.size().width / 2, frame.size().height));
		imshow("Left", Left);
		imshow("Right", Right);

		char key = waitKey(1);
		if (key == 27)break;
		if (key == 'q' || key == 'Q')						//按键Q存储
		{
			rightname = to_string(f) + "right.jpg";			//存储图片
			leftname  = to_str
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值