现可使用CNN分类器判断装甲板及其数字。

This commit is contained in:
xinyang
2019-04-20 14:30:57 +08:00
parent f891f1da34
commit 83e9a0daf9
5 changed files with 152 additions and 135 deletions

View File

@@ -12,16 +12,17 @@ IF(CCACHE_FOUND)
ENDIF()
FIND_PACKAGE(OpenCV 3 REQUIRED)
FIND_PACKAGE(Eigen3 REQUIRED)
FIND_PACKAGE(Threads)
include_directories( ${EIGEN3_INCLUDE_DIR} )
include_directories( ${PROJECT_SOURCE_DIR}/energy/include )
include_directories( ${PROJECT_SOURCE_DIR}/armor/include )
include_directories( ${PROJECT_SOURCE_DIR}/include )
include_directories( ${PROJECT_SOURCE_DIR}/src )
FILE(GLOB_RECURSE sourcefiles "src/*.cpp" "energy/src/*cpp" "armor/src/*.cpp")
FILE(GLOB_RECURSE sourcefiles "src/*.cpp" "energy/src/*cpp" "armor/src/*.cpp")
add_executable(run main.cpp ${sourcefiles} )
TARGET_LINK_LIBRARIES (run ${CMAKE_THREAD_LIBS_INIT})
TARGET_LINK_LIBRARIES(run ${CMAKE_THREAD_LIBS_INIT})
TARGET_LINK_LIBRARIES(run ${OpenCV_LIBS})
TARGET_LINK_LIBRARIES(run ${PROJECT_SOURCE_DIR}/libMVSDK.so)

View File

@@ -8,6 +8,7 @@
#include <opencv2/core.hpp>
#include <opencv2/tracking.hpp>
#include <uart/uart.h>
#include <armor_finder/classifier/classifier.h>
typedef enum{
ENEMY_BLUE, ENEMY_RED
@@ -15,7 +16,7 @@ typedef enum{
class ArmorFinder{
public:
ArmorFinder(EnemyColor color, Uart &u);
ArmorFinder(EnemyColor color, Uart &u, string paras_folder);
~ArmorFinder() = default;
private:
@@ -29,6 +30,9 @@ private:
State state;
cv::Rect2d armor_box;
cv::Ptr<cv::Tracker> tracker;
cv::Mat src_gray;
Classifier classifier;
int contour_area;
Uart &uart;

View File

@@ -4,10 +4,12 @@
#include <log.h>
#include <armor_finder/armor_finder.h>
ArmorFinder::ArmorFinder(EnemyColor color, Uart &u) :
ArmorFinder::ArmorFinder(EnemyColor color, Uart &u, string paras_folder) :
uart(u),
enemy_color(color),
state(STANDBY_STATE)
state(STANDBY_STATE),
classifier(std::move(paras_folder)),
contour_area(0)
{
auto para = TrackerToUse::Params();
para.desc_npca = 1;
@@ -25,6 +27,7 @@ void ArmorFinder::run(cv::Mat &src) {
}else{
src_use = src.clone();
}
cv::cvtColor(src_use, src_gray, CV_BayerBG2GRAY);
// return stateSearchingTarget(src_use);

View File

@@ -99,7 +99,7 @@ bool isCoupleLight(const LightBlob &light_blob_i, const LightBlob &light_blob_j)
}
double centerDistance(cv::Rect2d box){
double centerDistance(const cv::Rect2d &box){
double dx = box.x-box.width/2 - 320;
double dy = box.y-box.height/2 - 240;
return dx*dx + dy*dy;
@@ -169,14 +169,23 @@ bool ArmorFinder::stateSearchingTarget(cv::Mat &src) {
// }
if(show_light_blobs){
showContours("blobs", split, light_blobs);
// showContours("pm blobs", pmsrc, pm_light_blobs);
// showContours("blobs real", src, light_blobs_real);
cv::waitKey(1);
}
if(!findArmorBoxes(light_blobs, armor_boxes)){
return false;
}
if(classifier){
for(const auto &box : armor_boxes){
cv::Mat roi = src(box).clone();
cv::resize(roi, roi, cv::Size(60, 45));
if(classifier(roi)){
armor_box = box;
break;
}
}
}else{
armor_box = armor_boxes[0];
}
if(show_armor_boxes){
showArmorBoxVector("boxes", split, armor_boxes);
cv::waitKey(1);

View File

@@ -59,7 +59,7 @@ int main(int argc, char *argv[])
Mat energy_src, armor_src;
ArmorFinder armorFinder(ENEMY_BLUE, uart);
ArmorFinder armorFinder(ENEMY_BLUE, uart, "../paras/");
Energy energy(uart);
energy.setAllyColor(ally_color);