This commit is contained in:
sun
2019-07-09 21:04:30 +08:00
4 changed files with 26 additions and 22 deletions

View File

@@ -30,7 +30,7 @@ private:
typedef cv::TrackerKCF TrackerToUse; // Tracker类型定义
typedef enum{
WEAKSEARCHING_STATE, SEARCHING_STATE, TRACKING_STATE, STANDBY_STATE
SEARCHING_STATE, TRACKING_STATE, STANDBY_STATE
} State; // 自瞄状态枚举定义
const uint8_t &enemy_color; // 敌方颜色,引用外部变量,自动变化
@@ -41,8 +41,6 @@ private:
Classifier classifier; // CNN分类器对象实例用于数字识别
int contour_area; // 装甲区域亮点个数,用于数字识别未启用时判断是否跟丢(已弃用)
int tracking_cnt; // 记录追踪帧数,用于定时退出追踪
int miss_cnt; //
int weak_cnt; //
Serial &serial; // 串口对象,引用外部变量,用于和能量机关共享同一个变量
const uint8_t &use_classifier; // 标记是否启用CNN分类器引用外部变量自动变化

View File

@@ -1,6 +1,20 @@
//
// Created by xinyang on 19-3-27.
//
/*===========================================================================*/
/* 使用本代码的兵种 */
/*===========================================================================*/
/* _______________ _______________ _______________ _______________ */
/* | _____ | | _ _ | | ____ | | _____ | */
/* || |___ / || || | || | || || | ___| || || |___ | || */
/* || |_ \ || || | || |_ || || |___ \ || || / / || */
/* || ___) | || || |__ _| || || ___) | || || / / || */
/* || |____/ || || |_| || || |____/ || || /_/ || */
/* |_______________| |_______________| |_______________| |_______________| */
/* */
/*===========================================================================*/
#define LOG_LEVEL LOG_NONE
#include <log.h>
#include <options/options.h>
@@ -28,9 +42,7 @@ ArmorFinder::ArmorFinder(uint8_t &color, Serial &u, const string &paras_folder,
contour_area(0),
use_classifier(use),
boxid(-1),
tracking_cnt(0),
miss_cnt(0),
weak_cnt(0)
tracking_cnt(0)
{
}
@@ -44,16 +56,8 @@ void ArmorFinder::run(cv::Mat &src) {
// stateSearchingTarget(src_use); // for debug
// return;
switch (state){
case WEAKSEARCHING_STATE:
if(stateSearchingTarget(src_use) && ++weak_cnt>5){
miss_cnt = 0;
state = SEARCHING_STATE;
}else{
weak_cnt = 0;
}
case SEARCHING_STATE:
if(stateSearchingTarget(src_use)){
miss_cnt = 0;
if((armor_box & cv::Rect2d(0, 0, 640, 480)) == armor_box) { // 判断装甲板区域是否脱离图像区域
if(!classifier || !use_classifier){ /* 如果分类器不可用或者不使用分类器 */
cv::Mat roi = src_use.clone()(armor_box), roi_gray; /* 就使用装甲区域亮点数判断是否跟丢 */
@@ -67,14 +71,10 @@ void ArmorFinder::run(cv::Mat &src) {
tracking_cnt = 0;
LOGM(STR_CTR(WORD_LIGHT_CYAN, "into track"));
}
}else if(++miss_cnt>100){
weak_cnt = 0;
state = WEAKSEARCHING_STATE;
}
break;
case TRACKING_STATE:
if(!stateTrackingTarget(src_use) || ++tracking_cnt>100){ // 最多追踪100帧图像
miss_cnt = 0;
state = SEARCHING_STATE;
LOGM(STR_CTR(WORD_LIGHT_YELLOW ,"into search!"));
}

View File

@@ -291,7 +291,7 @@ bool ArmorFinder::stateSearchingTarget(cv::Mat &src) {
showArmorBoxVector("boxes", src, armor_boxes);
cv::waitKey(1);
}
if (classifier && use_classifier && state!=WEAKSEARCHING_STATE) {
if (classifier && use_classifier) {
for (auto box : armor_boxes) {
cv::Mat roi = src(box).clone();
cv::resize(roi, roi, cv::Size(48, 36));

View File

@@ -1,6 +1,12 @@
//
// Created by xixiliadorabarry on 1/24/19.
//
/*******************************************************************/
/* ____ _ _____ _ _ ____ __ __ ______ __ */
/*/ ___| | |_ _| | | | | _ \| \/ | / ___\ \ / / */
/*\___ \ _ | | | | | | | |_____| |_) | |\/| |_____| | \ \ / / */
/* ___) | |_| | | | | |_| |_____| _ <| | | |_____| |___ \ V / */
/*|____/ \___/ |_| \___/ |_| \_\_| |_| \____| \_/ */
/* */
/*******************************************************************/
#include <iostream>
#include <thread>
#include <opencv2/core/core.hpp>