Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the camera image acquisition and stitching program based on C++

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will introduce how to realize the camera image acquisition and stitching program based on C++. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.

Description of the program

To achieve real-time acquisition of a single frame image from the camera, and then complete the image stitching, this program realizes the stitching of two pictures and three pictures.

Before that, you need to install the opencv Package package under linux, because this program mainly uses the api function provided in the opencv package.

After capturing a single frame of video from different angles of view of the camera in real time and saving the real-time captured video file, the stitching of the image is completed. Due to the limited laboratory equipment, only two cameras on hand can only capture at a time.

Two single-frame images with different viewing angles, and the single-frame images we captured are saved in the frame1 and frame2 folders in the current project directory, so I made two completion programs at the same time.

Stitching program, one to achieve two different perspectives of image stitching, and the other to achieve three different perspectives of single-frame image stitching. The testusb.cpp file is the program for testing the camera. Before executing this procedure, you should make sure that there are two cameras plugged into the host port for real-time capture of a single frame of image.

Code introduction

Before compiling the program, please make sure that you have installed the opencv2.4.9 and pkg-config packages. This program is implemented on the ubuntu14.04 platform. In this project directory, there are compiled and generated executable programs, in which Camera_to_Frmae.cpp is the source code for us to capture a single frame image in real time from dual cameras.

ImageJoint.cpp, ImageJoint2.cpp and ImageJoint3.cpp respectively complete the stitching programs of two images with different visual angles and three images with different visual angles, of which three images stitched are ready-made images I found on the Internet.

Testusb.cpp is my program to test the camera.

Program compiling Gmail +-o dst src.cpp\ `pkg-config opencv-- cflags-- libs\ `execution and exit of the program

. / dst

When the program needs to exit, press Ctrl + C shortcut key

Effect.

Capture two single-frame images from the camera device

Image stitching effect picture

Add: C++ uses opencv to turn on the camera and save pictures

Project background

Use a usb binocular camera for binocular ranging project, this project code helps to use the usb binocular camera to turn on the camera and save pictures

Open the binocular camera function void SetCam (int weigth, int height, int num) {string a = "0"; string Error; VideoCapture Cam (0); / * set buffer size * / Cam.set (CV_CAP_PROP_FRAME_WIDTH, weigth); Cam.set (CV_CAP_PROP_FRAME_HEIGHT, height) While (! Cam.isOpened ()) {a = to_string (num); Error = "cannot open the camera1!"; Error = Error.replace (22,1, a); / / Error.copy (error, 24,0) / / here 5 means to copy a few characters, 0 represents the location of the copy,} / / namedWindow ("camera"); / / the key sentence code while (true) {Cam > > input_image;// passes the image into the picture leftImage = input_image (Rect (0,0, input_image.size (). Width / 2, input_image.size () .height) / / split left image rightImage = input_image (Rect (input_image.size (). Width / 2,0, input_image.size (). Width / 2, input_image.size () height); imshow ("leftImage", leftImage); / / left image imshow ("rightImage", rightImage); / / right image Save (I, 20) If (27 = = waitKey (30)) break; return;} Save picture function Savevoid Save (int & imgnum, int amount) {if (imgnum)

< amount) { a = to_string(imgnum); seat = floor((imgnum - 1) / 10); Left = Left.replace(4 + seat, 1, a); Right = Right.replace(5 + seat, 1, a); imwrite(Left, leftImage); imwrite(Right, rightImage); imgnum += 1; }} 全部代码 #include #includeusing namespace cv;using namespace std;VideoCapture Cam1, Cam2;const int weigth = 1280;const int height = 480;static string Left = "Left0.jpg", Right = "Right0.jpg", a = "0";static int seat = 0;static Mat input_image, leftImage, rightImage;static int i = 0;void Save(int &imgnum, int amount){ if (imgnum < amount) { a = to_string(imgnum); seat = floor((imgnum - 1) / 10); Left = Left.replace(4 + seat, 1, a); Right = Right.replace(5 + seat, 1, a); imwrite(Left, leftImage); imwrite(Right, rightImage); imgnum += 1; }}void SetCam(int weigth, int height, int num) string a = "0"; string Error; VideoCapture Cam(0); /*设定缓冲区大小*/ Cam.set(CV_CAP_PROP_FRAME_WIDTH, weigth); Cam.set(CV_CAP_PROP_FRAME_HEIGHT, height); while (!Cam.isOpened()) a = to_string(num); Error = "cannot open the camera1!"; Error = Error.replace(22, 1, a); //Error.copy(error, 24, 0);//这里5代表复制几个字符,0代表复制的位置, //namedWindow("摄像头");//关键一句代码 while (true) { Cam >

> input_image;// passes the image into the picture leftImage = input_image (Rect (0,0, input_image.size (). Width / 2, input_image.size () .height); / / split left image rightImage = input_image (Rect (input_image.size (). Width / 2,0, input_image.size (). Width / 2, input_image.size () .height)) Imshow ("leftImage", leftImage); / left image imshow ("rightImage", rightImage); / / right image Save (I, 20); if (27 = = waitKey (30)) break; return; void main () / / char* error = "error"; SetCam (weigth, height, 10) These are all the contents of the C++-based camera image acquisition and stitching program. More content related to how to achieve the C++-based camera image acquisition and stitching program can search the previous articles or browse the following articles to learn ha! I believe the editor will add more knowledge to you. I hope you can support it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report