当前位置:网站首页>Image mosaic camera mosaic notes
Image mosaic camera mosaic notes
2022-06-10 22:47:00 【AI vision netqi】
1、 be based on opencv3.4.1 Video mosaic algorithm developed , Integrated feature extraction 、 Two channel video automatic splicing algorithm ;
2、 Need to use vs2015, The graphics card runtime has been copied to the execution file , It can run directly , If further optimization is needed , You need to continue to improve yourself ;
3、 Fully open source , Due to the large project , So upload to the network disk , If you need it, you can download it ;
4、 Multithreading is used in the algorithm , If the master makes further improvement , Welcome to share .
SkyDrive address : link :https://pan.baidu.com/s/1TfB6ZWPFaWfn18MiXRyuvg password :ltct.
Link to the original text :https://blog.csdn.net/zhulong1984/article/details/80748202
Homography transformation is compared with translation transformation , It has wider scene adaptability , But at the same time, the stability will decline to a certain extent .
The technical details of the design are :
Feature detection and description
Feature matching and homography matrix estimation
opencv Video capture
Fade in fade out image fusion
The hardware requirements for this solution include : There are two USB Interface computer , Two reasonably placed USB camera .
Reasonable placement means : The two cameras are separated by a certain angle , The camera centers are close to each other , There is enough overlap in the scene . The above ensures the availability of homography transformation .
Code implementation :
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
# include "opencv2/features2d/features2d.hpp"
#include"opencv2/nonfree/nonfree.hpp"
#include"opencv2/calib3d/calib3d.hpp"
#include<iostream>
using namespace cv;
using namespace std;
int main()
{
VideoCapture cap1(0);
VideoCapture cap2(1);
double rate = 60;
int delay = 1000 / rate;
bool stop(false);
Mat img1;
Mat img2;
Mat result;
int d = 200;// Fade in fade out fusion width
Mat homography;
int k = 0;
namedWindow("cam1", CV_WINDOW_AUTOSIZE);
namedWindow("cam2", CV_WINDOW_AUTOSIZE);
namedWindow("stitch", CV_WINDOW_AUTOSIZE);
if (cap1.isOpened() && cap2.isOpened())
{
cout << "*** ***" << endl;
cout << " Camera activated !" << endl;
}
else
{
cout << "*** ***" << endl;
cout << " Warning : Please check whether the camera is installed properly !" << endl;
cout << " Program end !" << endl << "*** ***" << endl;
return -1;
}
cap1.set(CV_CAP_PROP_FOCUS, 0);
cap2.set(CV_CAP_PROP_FOCUS, 0);
while (!stop)
{
if (cap1.read(img1) && cap2.read(img2))
{
imshow("cam1", img1);
imshow("cam2", img2);
// Color frame to grayscale
//cvtColor(img1, img1, CV_RGB2GRAY);
//cvtColor(img2, img2, CV_RGB2GRAY);
// Calculate the homography matrix
if (k < 1 || waitKey(delay) == 13)
{
cout << " Matching ..." << endl;
vector<KeyPoint> keypoints1, keypoints2;
// Construction detector
//Ptr<FeatureDetector> detector = new ORB(120);
Ptr<FeatureDetector> detector = new SIFT(80);
detector->detect(img1, keypoints1);
detector->detect(img2, keypoints2);
// Construct descriptor extractor
Ptr<DescriptorExtractor> descriptor = detector;
// Extract descriptors
Mat descriptors1, descriptors2;
descriptor->compute(img1, keypoints1, descriptors1);
descriptor->compute(img2, keypoints2, descriptors2);
// Construct matcher
BFMatcher matcher(NORM_L2, true);
// Match descriptor
vector<DMatch> matches;
matcher.match(descriptors1, descriptors2, matches);
vector<Point2f> selPoints1, selPoints2;
vector<int> pointIndexes1, pointIndexes2;
for (vector<DMatch>::const_iterator it = matches.begin(); it != matches.end(); ++it)
{
selPoints1.push_back(keypoints1.at(it->queryIdx).pt);
selPoints2.push_back(keypoints2.at(it->trainIdx).pt);
}
vector<uchar> inliers(selPoints1.size(), 0);
homography = findHomography(selPoints1, selPoints2, inliers, CV_FM_RANSAC, 1.0);
// according to RANSAC Re filter matches
vector<DMatch> outMatches;
vector<uchar>::const_iterator itIn = inliers.begin();
vector<DMatch>::const_iterator itM = matches.begin();
for (; itIn != inliers.end(); ++itIn, ++itM)
{
if (*itIn)
{
outMatches.push_back(*itM);
}
}
k++;
// Draw the matching result
//Mat matchImage;
//drawMatches(img1, keypoints1, img2, keypoints2, outMatches, matchImage, 255, 255);
//imshow("match", matchImage);
///
}
// Splicing
double t = getTickCount();
warpPerspective(img1, result, homography, Size(2 * img1.cols-d, img1.rows));//Size Set the width of the resulting image , Cut a part of the width ,d Adjustable
Mat half(result, Rect(0, 0, img2.cols - d, img2.rows));
img2(Range::all(), Range(0, img2.cols - d)).copyTo(half);
for (int i = 0; i < d; i++)
{
result.col(img2.cols - d + i) = (d - i) / (float)d*img2.col(img2.cols - d + i) + i / (float)d*result.col(img2.cols - d + i);
}
imshow("stitch", result);
t = ((double)getTickCount() - t) / getTickFrequency();
//cout << t << endl;
}
else
{
cout << "----------------------" << endl;
cout << "waitting..." << endl;
}
if (waitKey(1) == 27)
{
stop = true;
cout << " Program end !" << endl;
cout << "*** ***" << endl;
}
}
return 0;
}
Experimental results :
The above video was recorded with screen recording software , The resolution will decrease . In practice , Direct observation shows good . Both input source images are 640*480 The resolution of the , It can be realized in real time . In my own i3 The processor is configured to run on a laptop , The display interval of the mosaic image is 0.10″~0.12″.
————————————————
Copyright notice : This paper is about CSDN Blogger 「czl389」 The original article of , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement .
Link to the original text :https://blog.csdn.net/czl389/article/details/60757000
边栏推荐
- 【TcaplusDB知识库】TcaplusDB查看进程所在机器介绍
- Innovation and exploration are added layer by layer, and the field model of intelligent process mining tends to be mature
- leetcode 130. Surrounded regions (medium)
- [tcapulusdb knowledge base] Introduction to tcapulusdb patrol inspection statistics
- Opencv_ 100 questions_ Chapter III (11-15)
- Tcapulusdb Jun · industry news collection (III)
- JVM runtime data area
- Differences between disk serial number, disk ID and volume serial number
- Solution to "XXX has broken path" error in idea
- 手机号码更新不出来,怎么处理
猜你喜欢

Differences between disk serial number, disk ID and volume serial number

C语言内功修炼【整型在内存中的存储】

【TcaplusDB知识库】TcaplusDB引擎参数调整介绍
![[tcapulusdb knowledge base] Introduction to tcapulusdb patrol inspection statistics](/img/67/e0112903cb3992a64bab02060dd59a.png)
[tcapulusdb knowledge base] Introduction to tcapulusdb patrol inspection statistics

Sealem finance builds Web3 decentralized financial platform infrastructure

鲸会务为智能化防疫工作赋能

【TcaplusDB知识库】TcaplusDB机器初始化和上架介绍
![[tcapulusdb knowledge base] tcapulusdb viewing online operation](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
[tcapulusdb knowledge base] tcapulusdb viewing online operation

Whale conference sharing: what should we do if the conference is difficult?

Add, delete, query and modify MySQL table structure (DDL)
随机推荐
[tcapulusdb knowledge base] tcapulusdb refresh tbus channel introduction
[tcapulusdb knowledge base] tcapulusdb tcapdb capacity expansion and contraction introduction
TcaplusDB君 · 行业新闻汇编(六)
1. Introduction to tornado & introduction to tornado project in this column
Blue Bridge Cup_ A fool sends a letter_ recursion
Web3生态去中心化金融平台——Sealem Finance
[tcapulusdb knowledge base] tcapulusdb tcapproxy capacity expansion introduction
Bitwise and shift operators
【TcaplusDB知识库】TcaplusDB进程启动介绍
CCF CSP 202109-4 collect cards
【006】初识字符串
Opencv_100问_第四章 (16-20)
CCF CSP 202109-1 array derivation
Opencv_100问_第二章 (6-10)
Simply Untyped Lambda Calculus的实现
Use of cocoeval function
Blue Bridge Cup_ Pick substring_ Combinatorial mathematics_ Multiplication principle/ Ruler method
小微企业如何低成本搭建微官网
C语言内功修炼【整型在内存中的存储】
Shell基础概念