177 lines
3.9 KiB
C++
177 lines
3.9 KiB
C++
|
#include<opencv2/opencv.hpp>
|
|||
|
#include <opencv2/highgui/highgui_c.h>
|
|||
|
#include<iostream>
|
|||
|
#include "tuneParameter.h"
|
|||
|
#include "preprocessing.h"
|
|||
|
#include "bufferTracker.h"
|
|||
|
#include "PnP.h"
|
|||
|
|
|||
|
using std::cout;
|
|||
|
using std::endl;
|
|||
|
|
|||
|
|
|||
|
////<2F><>ͣ <20><>ȡROI<4F><49><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
|
|||
|
//cv::Mat rawImages;
|
|||
|
//cv::Rect roiRect;
|
|||
|
//cv::Mat ROI;
|
|||
|
//cv::Point startPoint;
|
|||
|
//cv::Point endPoint;
|
|||
|
//bool downFlag = false;
|
|||
|
//bool upFlag = false;
|
|||
|
//
|
|||
|
//void MouseEvent(int event, int x, int y, int flags, void* data)
|
|||
|
//{
|
|||
|
//
|
|||
|
// if (event == cv::EVENT_LBUTTONDOWN)
|
|||
|
// {
|
|||
|
// downFlag = true;
|
|||
|
// startPoint.x = x;
|
|||
|
// startPoint.y = y;
|
|||
|
// }
|
|||
|
//
|
|||
|
// if (event == cv::EVENT_LBUTTONUP)
|
|||
|
// {
|
|||
|
// upFlag = true;
|
|||
|
// endPoint.x = x;
|
|||
|
// endPoint.y = y;
|
|||
|
// }
|
|||
|
//
|
|||
|
// if (downFlag == true && upFlag == false)
|
|||
|
// {
|
|||
|
// cv::Point tempPoint;
|
|||
|
// tempPoint.x = x;
|
|||
|
// tempPoint.y = y;
|
|||
|
//
|
|||
|
// cv::Mat tempImage = rawImages.clone();
|
|||
|
// rectangle(tempImage, startPoint, tempPoint, cv::Scalar(255, 0, 0), 2, 3, 0);
|
|||
|
// imshow("ROIing", tempImage);
|
|||
|
// }
|
|||
|
//
|
|||
|
// if (downFlag == true && upFlag == true)
|
|||
|
// {
|
|||
|
//
|
|||
|
// roiRect.width = abs(startPoint.x - endPoint.x);
|
|||
|
// roiRect.height = abs(startPoint.y - endPoint.y);
|
|||
|
// roiRect.x = min(startPoint.x, endPoint.x);
|
|||
|
// roiRect.y = min(startPoint.y, endPoint.y);
|
|||
|
// cout << roiRect.width << " " << roiRect.height << " " << roiRect.x << " " << roiRect.y << endl;
|
|||
|
// cv::Mat ROI(rawImages, roiRect);
|
|||
|
// imshow("ROI", ROI);
|
|||
|
// downFlag = false;
|
|||
|
// upFlag = false;
|
|||
|
// }
|
|||
|
// cv::waitKey(0);
|
|||
|
//
|
|||
|
//}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
int main() {
|
|||
|
std::basic_string<char> path = "./vedio/blue.mp4";
|
|||
|
cv::VideoCapture cap(path);
|
|||
|
bool paused = 0;
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
cv::Mat cameraMatrix;
|
|||
|
cv::Mat distCoeffs;
|
|||
|
|
|||
|
cv::FileStorage fs("./out_camera_data.xml", cv::FileStorage::READ);
|
|||
|
fs["camera_matrix"] >> cameraMatrix;
|
|||
|
fs["distortion_coefficients"] >> distCoeffs;
|
|||
|
|
|||
|
|
|||
|
if (cap.isOpened()) {
|
|||
|
cv::Rect roiRect;
|
|||
|
cv::Mat rawImages, ROI, mask;
|
|||
|
PreviousFrameInfo previousFrameInfo;
|
|||
|
std::chrono::high_resolution_clock::time_point previousFrameEndTime;
|
|||
|
|
|||
|
|
|||
|
while (true) {
|
|||
|
|
|||
|
//<2F>ж<EFBFBD><D0B6><EFBFBD>һ֡<D2BB><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
if (previousFrameInfo.firstFrame) {
|
|||
|
previousFrameEndTime = std::chrono::high_resolution_clock::now();
|
|||
|
previousFrameInfo.firstFrame = false;
|
|||
|
}
|
|||
|
else {
|
|||
|
auto t = std::chrono::high_resolution_clock::now();
|
|||
|
previousFrameInfo.elapsedTime = std::chrono::high_resolution_clock::now() - previousFrameEndTime;
|
|||
|
previousFrameEndTime = t;
|
|||
|
}
|
|||
|
|
|||
|
vector<cv::Point2f> targetPoints;
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>Դ<EFBFBD>Ķ<EFBFBD>ȡ
|
|||
|
if (!paused) {
|
|||
|
cap >> rawImages;
|
|||
|
//<2F><>ͣ<EFBFBD><CDA3>Ƶ
|
|||
|
if (rawImages.empty())
|
|||
|
break;
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>
|
|||
|
roiRect.width = 605;
|
|||
|
roiRect.height = 500;
|
|||
|
/*roiRect.x = 154;
|
|||
|
roiRect.y = 176;*/
|
|||
|
roiRect.x = 125;
|
|||
|
roiRect.y = 80;
|
|||
|
cv::Mat ROI(rawImages, roiRect);
|
|||
|
|
|||
|
//ͼ<><CDBC>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
|
|||
|
mask = preprocessing(ROI);
|
|||
|
//Ѱ<><D1B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
targetPoints = findTarget(ROI, previousFrameInfo, mask);
|
|||
|
//Ԥ<><D4A4> <20>ȴ<EFBFBD>ʱ<EFBFBD><CAB1>...<2E><>...<2E><><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
//λ<>˽<EFBFBD><CBBD><EFBFBD>
|
|||
|
PNP(ROI, targetPoints, cameraMatrix, distCoeffs);
|
|||
|
|
|||
|
cv::namedWindow("rawImages", 0);
|
|||
|
//resizeWindow("rawImages", 741, 620);
|
|||
|
imshow("rawImages", ROI);
|
|||
|
cv::waitKey(1);
|
|||
|
}
|
|||
|
// <20><>q<EFBFBD>˳<EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ո<EFBFBD><D5B8><EFBFBD>ͣ<EFBFBD><CDA3>Ƶ<EFBFBD><C6B5><EFBFBD>е<EFBFBD><D0B5><EFBFBD>
|
|||
|
char key = cv::waitKey(1);
|
|||
|
if (key == 'q')
|
|||
|
break;
|
|||
|
else if (key == ' ') {
|
|||
|
paused = !paused;
|
|||
|
////<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>Ȥ<EFBFBD><C8A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
//namedWindow("ROIing");
|
|||
|
//resizeWindow("ROIing", 741, 620);
|
|||
|
//imshow("ROIing", rawImages);
|
|||
|
//setMouseCallback("ROIing", MouseEvent, 0);
|
|||
|
//waitKey(0);
|
|||
|
|
|||
|
////<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>
|
|||
|
//roiRect.width = 605;
|
|||
|
//roiRect.height = 500;
|
|||
|
///*roiRect.x = 154;
|
|||
|
//roiRect.y = 176;*/
|
|||
|
//roiRect.x = 125;
|
|||
|
//roiRect.y = 80;
|
|||
|
//Mat ROI(rawImages, roiRect);
|
|||
|
////<2F><><EFBFBD><EFBFBD>
|
|||
|
//tuneParameter(ROI);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
cout << "<EFBFBD><EFBFBD>Ƶͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
|
|||
|
//<2F>ͷ<EFBFBD><CDB7><EFBFBD>Ƶ<EFBFBD><C6B5>Դ
|
|||
|
cap.release();
|
|||
|
}
|
|||
|
else
|
|||
|
cout << "<EFBFBD><EFBFBD>Ƶͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>" << endl;
|
|||
|
|
|||
|
return 0;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|