反小陀螺前置代码已完成。
This commit is contained in:
@@ -1,13 +1,30 @@
|
||||
#include <show_images/show_images.h>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <options/options.h>
|
||||
#include <log.h>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
|
||||
void drawLightBlobs(cv::Mat &src, const LightBlobs &blobs){
|
||||
for (const auto &blob:blobs) {
|
||||
Scalar color(0,255,0);
|
||||
if (blob.blob_color == BLOB_RED)
|
||||
color = Scalar(0, 0, 255);
|
||||
else if (blob.blob_color == BLOB_BLUE)
|
||||
color = Scalar(255, 0, 0);
|
||||
cv::Point2f vertices[4];
|
||||
blob.rect.points(vertices);
|
||||
for (int j = 0; j < 4; j++) {
|
||||
cv::line(src, vertices[j], vertices[(j + 1) % 4], color, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**************************
|
||||
* 显示多个装甲板区域 *
|
||||
**************************/
|
||||
void showArmorBoxVector(std::string windows_name, const cv::Mat &src, const std::vector<cv::Rect2d> &armor_box) {
|
||||
void showArmorBoxes(std::string windows_name, const cv::Mat &src, const ArmorBoxes &armor_boxes) {
|
||||
static Mat image2show;
|
||||
if (src.type() == CV_8UC1) {// 黑白图像
|
||||
cvtColor(src, image2show, COLOR_GRAY2RGB);
|
||||
@@ -15,8 +32,15 @@ void showArmorBoxVector(std::string windows_name, const cv::Mat &src, const std:
|
||||
image2show = src.clone();
|
||||
}
|
||||
|
||||
for (auto &box:armor_box) {
|
||||
rectangle(image2show, box, Scalar(0, 255, 0), 1);
|
||||
for (auto &box:armor_boxes) {
|
||||
if(box.box_color == BOX_BLUE) {
|
||||
rectangle(image2show, box.rect, Scalar(0, 255, 0), 1);
|
||||
drawLightBlobs(image2show, box.light_blobs);
|
||||
}else if(box.box_color == BOX_RED){
|
||||
rectangle(image2show, box.rect, Scalar(0, 255, 0), 1);
|
||||
drawLightBlobs(image2show, box.light_blobs);
|
||||
}
|
||||
|
||||
}
|
||||
imshow(windows_name, image2show);
|
||||
}
|
||||
@@ -24,25 +48,26 @@ void showArmorBoxVector(std::string windows_name, const cv::Mat &src, const std:
|
||||
/**************************
|
||||
* 显示多个装甲板区域及其类别 *
|
||||
**************************/
|
||||
void showArmorBoxClass(std::string window_names, const cv::Mat &src, vector<cv::Rect2d> boxes[10]) {
|
||||
void showArmorBoxesClass(std::string window_names, const cv::Mat &src, const ArmorBoxes boxes[15]) {
|
||||
static Mat image2show;
|
||||
if (src.type() == CV_8UC1) { // 黑白图像
|
||||
cvtColor(src, image2show, COLOR_GRAY2RGB);
|
||||
} else if (src.type() == CV_8UC3) { //RGB 彩色
|
||||
image2show = src.clone();
|
||||
}
|
||||
for (int i = 0; i < 14; i++) {
|
||||
for (int i = 1; i < 15; i++) {
|
||||
if (!boxes[i].empty()) {
|
||||
for (auto box : boxes[i]) {
|
||||
rectangle(image2show, box, Scalar(0, 255, 0), 1);
|
||||
rectangle(image2show, box.rect, Scalar(0, 255, 0), 1);
|
||||
drawLightBlobs(image2show, box.light_blobs);
|
||||
if (i == -1)
|
||||
putText(image2show, id2name[i], Point(box.x + 2, box.y + 2), cv::FONT_HERSHEY_TRIPLEX, 1,
|
||||
putText(image2show, id2name[i], Point(box.rect.x + 2, box.rect.y + 2), cv::FONT_HERSHEY_TRIPLEX, 1,
|
||||
Scalar(0, 255, 0));
|
||||
else if (1 <= i && i < 8)
|
||||
putText(image2show, id2name[i], Point(box.x + 2, box.y + 2), cv::FONT_HERSHEY_TRIPLEX, 1,
|
||||
putText(image2show, id2name[i], Point(box.rect.x + 2, box.rect.y + 2), cv::FONT_HERSHEY_TRIPLEX, 1,
|
||||
Scalar(255, 0, 0));
|
||||
else if (8 <= i && i < 15)
|
||||
putText(image2show, id2name[i], Point(box.x + 2, box.y + 2), cv::FONT_HERSHEY_TRIPLEX, 1,
|
||||
putText(image2show, id2name[i], Point(box.rect.x + 2, box.rect.y + 2), cv::FONT_HERSHEY_TRIPLEX, 1,
|
||||
Scalar(0, 0, 255));
|
||||
else if (i != 0)
|
||||
LOGE_INFO("Invalid box id:%d!", i);
|
||||
@@ -55,34 +80,47 @@ void showArmorBoxClass(std::string window_names, const cv::Mat &src, vector<cv::
|
||||
/**************************
|
||||
* 显示单个装甲板区域及其类别 *
|
||||
**************************/
|
||||
void showArmorBox(std::string windows_name, const cv::Mat &src, cv::Rect2d armor_box, int boxid) {
|
||||
void showArmorBox(std::string windows_name, const cv::Mat &src, const ArmorBox &box) {
|
||||
static Mat image2show;
|
||||
if(box.rect == cv::Rect2d()){
|
||||
imshow(windows_name, src);
|
||||
}
|
||||
if (src.type() == CV_8UC1) { // 黑白图像
|
||||
cvtColor(src, image2show, COLOR_GRAY2RGB);
|
||||
} else if (src.type() == CV_8UC3) { //RGB 彩色
|
||||
image2show = src.clone();
|
||||
}
|
||||
rectangle(image2show, armor_box, Scalar(0, 255, 0), 1);
|
||||
drawLightBlobs(image2show, box.light_blobs);
|
||||
// static FILE *fp = fopen(PROJECT_DIR"/ratio.txt", "w");
|
||||
// if(box.light_blobs.size() == 2)
|
||||
// fprintf(fp, "%lf %lf %lf\n", box.light_blobs[0].length, box.light_blobs[1].length, box.blobsDistance())
|
||||
cout << box.rect.width/box.rect.height << endl;
|
||||
if(box.rect.width/box.rect.height > 1.6){
|
||||
rectangle(image2show, box.rect, Scalar(0, 255, 0), 3);
|
||||
}else{
|
||||
rectangle(image2show, box.rect, Scalar(0, 255, 0), 1);
|
||||
};
|
||||
|
||||
char dist[5];
|
||||
// sprintf(dist, "%.1f", distance);
|
||||
if (boxid == -1)
|
||||
putText(image2show, id2name[boxid]+" "+dist, Point(armor_box.x + 2, armor_box.y + 2), cv::FONT_HERSHEY_TRIPLEX, 1,
|
||||
if (box.id == -1)
|
||||
putText(image2show, id2name[box.id]+" "+dist, Point(box.rect.x + 2, box.rect.y + 2), cv::FONT_HERSHEY_TRIPLEX, 1,
|
||||
Scalar(0, 255, 0));
|
||||
else if (1 <= boxid && boxid < 8)
|
||||
putText(image2show, id2name[boxid]+" "+dist, Point(armor_box.x + 2, armor_box.y + 2), cv::FONT_HERSHEY_TRIPLEX, 1,
|
||||
else if (1 <= box.id && box.id < 8)
|
||||
putText(image2show, id2name[box.id]+" "+dist, Point(box.rect.x + 2, box.rect.y + 2), cv::FONT_HERSHEY_TRIPLEX, 1,
|
||||
Scalar(255, 0, 0));
|
||||
else if (8 <= boxid && boxid < 15)
|
||||
putText(image2show, id2name[boxid]+" "+dist, Point(armor_box.x + 2, armor_box.y + 2), cv::FONT_HERSHEY_TRIPLEX, 1,
|
||||
else if (8 <= box.id && box.id < 15)
|
||||
putText(image2show, id2name[box.id]+" "+dist, Point(box.rect.x + 2, box.rect.y + 2), cv::FONT_HERSHEY_TRIPLEX, 1,
|
||||
Scalar(0, 0, 255));
|
||||
else if (boxid != 0)
|
||||
LOGE_INFO("Invalid box id:%d!", boxid);
|
||||
else if (box.id != 0)
|
||||
LOGE_INFO("Invalid box id:%d!", box.id);
|
||||
imshow(windows_name, image2show);
|
||||
}
|
||||
|
||||
/**************************
|
||||
* 显示多个灯条区域 *
|
||||
**************************/
|
||||
void showContours(std::string windows_name, const cv::Mat &src, const std::vector<LightBlob> &light_blobs) {
|
||||
void showLightBlobs(std::string windows_name, const cv::Mat &src, const LightBlobs &light_blobs) {
|
||||
static Mat image2show;
|
||||
|
||||
if (src.type() == CV_8UC1) { // 黑白图像
|
||||
@@ -92,13 +130,11 @@ void showContours(std::string windows_name, const cv::Mat &src, const std::vecto
|
||||
}
|
||||
|
||||
for (const auto &light_blob:light_blobs) {
|
||||
Scalar color;
|
||||
if (light_blob.BlobColor == BLOB_RED)
|
||||
Scalar color(0, 255, 0);
|
||||
if (light_blob.blob_color == BLOB_RED)
|
||||
color = Scalar(0, 0, 255);
|
||||
else if (light_blob.BlobColor == BLOB_BLUE)
|
||||
else if (light_blob.blob_color == BLOB_BLUE)
|
||||
color = Scalar(255, 0, 0);
|
||||
else
|
||||
color = Scalar(0, 255, 0);
|
||||
cv::Point2f vertices[4];
|
||||
light_blob.rect.points(vertices);
|
||||
for (int j = 0; j < 4; j++) {
|
||||
@@ -107,3 +143,15 @@ void showContours(std::string windows_name, const cv::Mat &src, const std::vecto
|
||||
}
|
||||
imshow(windows_name, image2show);
|
||||
}
|
||||
|
||||
|
||||
void showTrackSearchingPos(std::string window_names, const cv::Mat &src, const cv::Rect2d pos){
|
||||
static Mat image2show;
|
||||
if (src.type() == CV_8UC1) { // 黑白图像
|
||||
cvtColor(src, image2show, COLOR_GRAY2RGB);
|
||||
} else if (src.type() == CV_8UC3) { //RGB 彩色
|
||||
image2show = src.clone();
|
||||
}
|
||||
rectangle(image2show, pos, Scalar(0, 255, 0), 1);
|
||||
imshow(window_names, image2show);
|
||||
}
|
||||
Reference in New Issue
Block a user