rm记录第二阶段(二):Armor分析(二)

最后一个类了,继续干!还有就是.h里面的一些函数是单独出来的这个一会也会说到

class ArmorDetector
{
public:
	ArmorDetector();
	~ArmorDetector();
	/**
	 * @brief: load svm model for client
	 * @param: the model file path of svm
	 */
	void loadSVM(const char * model_path, Size armorImgSize = Size(40, 40));

	/**
	 * @brief: set enemyColor  设置敌方颜色
	 */
	void setEnemyColor(Color enemyColor);

	/**
	 *@brief: for client, set the target armor number 操作手用,设置目标装甲板数字
	 */
	void setTargetNum(const int & targetNum);

	/**
	 *@brief: reset the ArmorDetector(delete the priviois lights and armors) to start next frame detection 重设检测器(删除原有的灯条和装甲板s)和装甲板状态,以便进行下一帧的检测
	 */
	void resetDetector();

	/**
	 * @brief: load source image and set roi if roiMode is open and found target in last frame 载入源图像并进行图像预处理
	 * @param: const Mat& src     源图像的引用
	 */
    void setImg(Mat & src);

	/**
	 * @brief: find all the possible lights of armor (get lights) 检测所有可能的灯条
	 */
	void findLights();

	/**
	* @brief: match lights into armors (get armors) 将识别到的灯条拟合为装甲板
	*/
	void matchArmors();

	/**
	 *@brief: set the privious targetArmor as lastArmor and then choose the most valuable armor from current armors as targetArmor (set targetArmor and lastArmor)
	 *			将上一帧的目标装甲板作为lastArmor选择本帧图像中所有装甲板里面价值最大的装甲板作为目标装甲板
	 */
	void setTargetArmor();

	/**
	 *@brief: an integrative function to run the Detector 集成的装甲板检测识别函数
	 */
    void run(Mat & src);

    /**
     *@brief: return the Detector status 识别程序是否识别到装甲版
     *@return: FOUND(1) NOT_FOUND(0)
     */
    bool isFoundArmor();

	/**
	 *@brief: show all the informations of this frame detection  显示所有信息
	 */
	void showDebugInfo(bool showSrcImg_ON, bool showSrcBinary_ON, bool showLights_ON, bool showArmors_ON, bool textLights_ON, bool textArmors_ON, bool textScores_ON);


	/**
	 *@brief: get the vertices and type of target Armor for angle solver 将detector的结果输出
	 */
    void getTargetInfo(vector<Point2f> &armorVertices, Point2f &centerPoint, ArmorType &type);

private:
	Mat srcImg;  //source image (current frame acquired from camera) 从相机采集的当前的图像帧
	Mat srcImg_binary; //binary image of srcImg 源图像的二值图
	Color enemyColor;  //the color of enemy 敌方颜色
	int targetNum; //number of client's target armor 操作手设定的目标装甲板数字
	vector<LightBar> lights; //all the lightBars find in roiIng 找到的灯条
	vector<ArmorBox> armors; //all the armors matched from lights 识别到的所有装甲板
	ArmorBox targetArmor; //current target for current frame 当前图像帧对应的目标装甲板
	ArmorBox lastArmor;  //previous target for last frame 上一帧图像的目标装甲板
	ArmorNumClassifier classifier; //class used to get armorImg and classifier the armorNum 获取装甲板图像及识别装甲板数字的类
	DetectorState state; //the state of detector updating along with the program running 装甲板检测器的状态,随着装甲板进程的执行而不断更新 
};

先看属性:原图像,二值化,颜色,数字,识别到的灯条,装甲板,当前帧的装甲板,上一帧的,获取图像识别数字,状态。

然后第一个函数还是初始化的:设定状态为未发现

ArmorDetector::ArmorDetector()
{
    state = LIGHTS_NOT_FOUND;
}

然后:放入模型

void ArmorDetector::loadSVM(const char * model_path, Size armorImgSize)
{
	classifier.loadSvmModel(model_path, armorImgSize);
}

设置颜色,数字

/**
* @brief: set enemyColor  设置敌方颜色
*/
void ArmorDetector::setEnemyColor(Color enemyColor){
	this->enemyColor = enemyColor;
}

/**
* @brief: set enemyNum  设置目标装甲板数字
*/
void ArmorDetector::setTargetNum(const int & targetNum)
{
	this->targetNum = targetNum;
}

重置

void ArmorDetector::resetDetector()
{
	state = LIGHTS_NOT_FOUND;
	lights.clear();
	armors.clear();
}

然后看一下这个函数:先是对原图像复制拷贝一下,然后对其进行预处理,建立一个同样大小的全是0图像矩阵,然后就是通道相减,这里用的指针,加快了速度,然后建立一个核后进行膨胀操作

void ArmorDetector::setImg(Mat & src){
	src.copyTo(srcImg);  //deep copy src to srcImg 深(值)拷贝给srcImg
	classifier.loadImg(srcImg); //srcImg for classifier, warp perspective  载入classifier类成员的srcImg,用于透射变换剪切出装甲板图
	srcImg_binary = Mat::zeros(srcImg.size(), CV_8UC1); //color feature image

	//pointer visits all the data of srcImg, the same to bgr channel split 通道相减法的自定义形式&
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值