Skip to content

Commit 4d643c1

Browse files
committed
修改了相机的ROI参数
1 parent c4214eb commit 4d643c1

File tree

10 files changed

+55
-7
lines changed

10 files changed

+55
-7
lines changed

image/12_5/res_match_knn_0452.png

1.8 MB
Loading

image/12_5/top_0.png

2.49 MB
Loading

image/12_5/top_1.png

2.49 MB
Loading

image/12_5/top_2.png

2.49 MB
Loading

image/12_5/top_3.png

2.49 MB
Loading

lib/Galaxy/include/CameraBot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class CameraBot : public GxCamera {
2222
std::vector<float> GetHorizontalLine(cv::Mat img);
2323
std::vector<cv::Point2f> GetModelPoints(cv::Mat img);
2424
double GetDistance(cv::Mat img, std::vector<float> line_params);
25+
void GetMapParam(cv::Mat Calibration_board);
2526

2627
private:
2728
double _mapParam;

lib/Galaxy/src/CameraBot.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,43 @@ double CameraBot::GetDistance(cv::Mat img, std::vector<float> line_params) {
124124
return distance * _mapParam + 0.3;
125125
}
126126

127+
/**
128+
* @brief 获取相机映射参数,只标定z轴
129+
*
130+
* @param Calibration_board 标定板图,灰度
131+
*/
132+
void CameraBot::GetMapParam(cv::Mat Calibration_board) {
133+
std::vector<cv::Point2f> corner;
134+
if (!cv::findChessboardCorners(Calibration_board, cv::Size(19, 15), corner)) {
135+
std::cerr << "Failed to find corners in image" << std::endl;
136+
return;
137+
}
138+
const cv::TermCriteria criteria{cv::TermCriteria::EPS | cv::TermCriteria::COUNT, 30, 0.001};
139+
cv::cornerSubPix(Calibration_board, corner, cv::Size(6, 6), cv::Size(-1, -1), criteria);
140+
cv::drawChessboardCorners(Calibration_board, cv::Size(19, 15), corner, true);
141+
142+
std::string imagename = "Calibration_board";
143+
cv::namedWindow(imagename, cv::WINDOW_NORMAL);
144+
cv::resizeWindow(imagename, cv::Size(1295, 1024));
145+
cv::imshow(imagename, Calibration_board);
146+
147+
float sum = 0;
148+
cv::Point2f last_point{};
149+
for (int i = 0; i < 19; ++i) {
150+
for (int j = 0; j < 15; ++j) {
151+
if (j == 0) {
152+
last_point = corner[j * 19 + i];
153+
continue;
154+
}
155+
auto a = sqrt(powf(corner[j * 19 + i].x - last_point.x, 2) + powf(corner[j * 19 + i].y - last_point.y, 2));
156+
sum += a;
157+
last_point = corner[j * 19 + i];
158+
}
159+
}
160+
float map_param = 14 * 19 / sum;
161+
std::cout << "map_param: " << map_param << " (mm/pixel)" << std::endl;
162+
cv::waitKey(0);
163+
}
164+
127165
CameraBot::~CameraBot() {}
128166
} // namespace D5R

lib/Galaxy/src/CameraTop.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,12 @@ bool D5R::CameraTop::SIFT(cv::Mat image, ModelType modelname,
173173
keyPoints_Model = _jaw.keypoints;
174174
descriptors_model = _jaw.descriptors;
175175
}
176+
176177
// ROI
177-
cv::Point2f roiP(800, 648);
178-
cv::Rect roi = cv::Rect(roiP, cv::Size(750, 1400));
178+
cv::Point2f roiP(450, 700);
179+
cv::Rect roi = cv::Rect(roiP, cv::Size(750, 1348));
179180
cv::Mat ROI = image(roi).clone();
181+
180182
// SIFT特征点
181183
cv::Ptr<cv::SIFT> sift = cv::SIFT::create();
182184
std::vector<cv::KeyPoint> keyPoints_Img;

test/Match.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
int main() {
44
cv::Mat model = cv::imread("../image/11_22/jaw_model.png", 0);
5-
cv::Mat image = cv::imread("../image/11_22/jaw0.png");
5+
cv::Mat image = cv::imread("../image/12_5/top_1.png");
66
if (image.empty()) {
77
std::cerr << "Failed to load model " << std::endl;
88
return -1;
99
}
10-
cv::Rect roi = cv::Rect(800, 648, 750, 1400);
10+
cv::Point2f D(450, 700);
11+
cv::Rect roi = cv::Rect(450, 700, 750, 1348);
1112
cv::Mat ROI = image(roi).clone();
1213

1314
cv::Ptr<cv::SIFT> sift = cv::SIFT::create();
@@ -61,17 +62,17 @@ int main() {
6162
std::vector<cv::Point2f> modelPosition = {cv::Point2f(318, 408.5), cv::Point2f(318, 44)};
6263
std::vector<cv::Point2f> ImgPosition;
6364
cv::perspectiveTransform(modelPosition, ImgPosition, homography);
64-
cv::line(image, ImgPosition[0] + cv::Point2f(800, 648), ImgPosition[1] + cv::Point2f(800, 648), cv::Scalar(0, 0, 255), 2);
65+
cv::line(image, ImgPosition[0] + D, ImgPosition[1] + D, cv::Scalar(0, 0, 255), 2);
6566
float angle = atan2f((ImgPosition[0].y - ImgPosition[1].y), (ImgPosition[0].x - ImgPosition[1].x)) * (-180) / CV_PI;
66-
cv::putText(image, std::to_string(angle), ImgPosition[0] + cv::Point2f(800, 648), cv::FONT_HERSHEY_SIMPLEX, 1.5, cv::Scalar(0, 0, 255), 2);
67+
cv::putText(image, std::to_string(angle), ImgPosition[0] + D, cv::FONT_HERSHEY_SIMPLEX, 1.5, cv::Scalar(0, 0, 255), 2);
6768

6869
int64 end = cv::getTickCount();
6970
std::cout << 1000.0 * (end - start) / cv::getTickFrequency() << std::endl;
7071

7172
cv::Mat img_matches_knn;
7273
cv::drawMatches(model, keyPoints_Model, ROI, keyPoints_Img, goodMatches, img_matches_knn, cv::Scalar::all(-1),
7374
cv::Scalar::all(-1), std::vector<char>(), cv::DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
74-
cv::imwrite("../image/11_22/res_match_knn_0452.png", img_matches_knn);
75+
cv::imwrite("../image/12_5/res_match_knn_0452.png", img_matches_knn);
7576
std::string windowname2 = "Match res";
7677
cv::namedWindow(windowname2, cv::WINDOW_NORMAL);
7778
cv::resizeWindow(windowname2, cv::Size(1295, 1024));

todolist.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
调试dev代码
2+
设置电机旋转零点
3+
获取bot相机的视图,主要是钳口库的,更改直线获取函数
4+
5+
6+
RMD电机调PI(不急)

0 commit comments

Comments
 (0)