fix bug.
This commit is contained in:
@@ -86,43 +86,3 @@ void ArmorFinder::run(cv::Mat &src) {
|
||||
}
|
||||
}
|
||||
|
||||
bool sendTarget(Serial &serial, double x, double y, double z) {
|
||||
static short x_tmp, y_tmp, z_tmp;
|
||||
static time_t last_time = time(nullptr);
|
||||
static int fps;
|
||||
uint8_t buff[8];
|
||||
|
||||
time_t t = time(nullptr);
|
||||
if (last_time != t) {
|
||||
last_time = t;
|
||||
cout << "fps:" << fps << ", (" << x << "," << y << "," << z << ")" << endl;
|
||||
fps = 0;
|
||||
}
|
||||
fps += 1;
|
||||
|
||||
x_tmp = static_cast<short>(x * (32768 - 1) / 100);
|
||||
y_tmp = static_cast<short>(y * (32768 - 1) / 100);
|
||||
z_tmp = static_cast<short>(z * (32768 - 1) / 1000);
|
||||
|
||||
buff[0] = 's';
|
||||
buff[1] = static_cast<char>((x_tmp >> 8) & 0xFF);
|
||||
buff[2] = static_cast<char>((x_tmp >> 0) & 0xFF);
|
||||
buff[3] = static_cast<char>((y_tmp >> 8) & 0xFF);
|
||||
buff[4] = static_cast<char>((y_tmp >> 0) & 0xFF);
|
||||
buff[5] = static_cast<char>((z_tmp >> 8) & 0xFF);
|
||||
buff[6] = static_cast<char>((z_tmp >> 0) & 0xFF);
|
||||
buff[7] = 'e';
|
||||
|
||||
return serial.WriteData(buff, sizeof(buff));
|
||||
}
|
||||
|
||||
bool ArmorFinder::sendBoxPosition() {
|
||||
auto rect = armor_box;
|
||||
double dx = rect.x + rect.width / 2 - 320;
|
||||
double dy = rect.y + rect.height / 2 - 240 - 20;
|
||||
double yaw = atan(dx / FOCUS_PIXAL) * 180 / PI;
|
||||
double pitch = atan(dy / FOCUS_PIXAL) * 180 / PI;
|
||||
double dist = DISTANCE_HEIGHT / armor_box.height;
|
||||
// cout << yaw << endl;
|
||||
return sendTarget(serial, yaw, -pitch, dist);
|
||||
}
|
||||
@@ -21,7 +21,7 @@ bool rectangleContainPoint(cv::RotatedRect rectangle, cv::Point2f point) {
|
||||
return indicator >= 0;
|
||||
}
|
||||
|
||||
/// Todo: 下面的函数可以有性能优化,暂时未做。
|
||||
// 下面的函数可以有性能优化,暂时未做。
|
||||
static double nonZeroRateOfRotateRect(const cv::Mat &bin, const cv::RotatedRect &rotrect) {
|
||||
auto rect = rotrect.boundingRect();
|
||||
if (rect.x < 0 || rect.y < 0 || rect.x + rect.width > bin.cols || rect.y + rect.height > bin.rows) {
|
||||
@@ -45,7 +45,7 @@ int linePointX(const cv::Point2f &p1, const cv::Point2f &p2, int y) {
|
||||
return (p2.x - p1.x) / (p2.y - p1.y) * (y - p1.y) + p1.x;
|
||||
}
|
||||
|
||||
///Todo: 性能优化后的函数。(暂时还有点问题)
|
||||
// 性能优化后的函数
|
||||
static double nonZeroRateOfRotateRect_opt(const cv::Mat &bin, const cv::RotatedRect &rotrect) {
|
||||
int cnt = 0;
|
||||
cv::Point2f corners[4];
|
||||
|
||||
46
armor/src/armor_finder/send_target/send_target.cpp
Normal file
46
armor/src/armor_finder/send_target/send_target.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// Created by xinyang on 19-7-11.
|
||||
//
|
||||
|
||||
#include <armor_finder/armor_finder.h>
|
||||
|
||||
static bool sendTarget(Serial &serial, double x, double y, double z) {
|
||||
static short x_tmp, y_tmp, z_tmp;
|
||||
static time_t last_time = time(nullptr);
|
||||
static int fps;
|
||||
uint8_t buff[8];
|
||||
|
||||
time_t t = time(nullptr);
|
||||
if (last_time != t) {
|
||||
last_time = t;
|
||||
cout << "fps:" << fps << ", (" << x << "," << y << "," << z << ")" << endl;
|
||||
fps = 0;
|
||||
}
|
||||
fps += 1;
|
||||
|
||||
x_tmp = static_cast<short>(x * (32768 - 1) / 100);
|
||||
y_tmp = static_cast<short>(y * (32768 - 1) / 100);
|
||||
z_tmp = static_cast<short>(z * (32768 - 1) / 1000);
|
||||
|
||||
buff[0] = 's';
|
||||
buff[1] = static_cast<char>((x_tmp >> 8) & 0xFF);
|
||||
buff[2] = static_cast<char>((x_tmp >> 0) & 0xFF);
|
||||
buff[3] = static_cast<char>((y_tmp >> 8) & 0xFF);
|
||||
buff[4] = static_cast<char>((y_tmp >> 0) & 0xFF);
|
||||
buff[5] = static_cast<char>((z_tmp >> 8) & 0xFF);
|
||||
buff[6] = static_cast<char>((z_tmp >> 0) & 0xFF);
|
||||
buff[7] = 'e';
|
||||
|
||||
return serial.WriteData(buff, sizeof(buff));
|
||||
}
|
||||
|
||||
bool ArmorFinder::sendBoxPosition() {
|
||||
auto rect = armor_box;
|
||||
double dx = rect.x + rect.width / 2 - 320;
|
||||
double dy = rect.y + rect.height / 2 - 240 - 20;
|
||||
double yaw = atan(dx / FOCUS_PIXAL) * 180 / PI;
|
||||
double pitch = atan(dy / FOCUS_PIXAL) * 180 / PI;
|
||||
double dist = DISTANCE_HEIGHT / rect.height;
|
||||
// cout << yaw << endl;
|
||||
return sendTarget(serial, yaw, -pitch, dist);
|
||||
}
|
||||
Reference in New Issue
Block a user