TA的每日心情 | 开心 昨天 22:46 |
---|
签到天数: 596 天 连续签到: 3 天 [LV.9]以坛为家II
|
本帖最后由 robe.zhang 于 2020-12-27 01:38 编辑
【米尔FZ3深度学习计算卡】鼠标检测源码 + 视频
鼠标检测视频:
百度 EasyDL 训练数据集采集视频:
鼠标检测视频源码:
- /***************************************************************************
- *
- * Copyright (c) 2020 Robe. All Rights Reserved
- *
- **************************************************************************/
- /**
- * @author: Robe
- * @brief: video detection.
- * suit for SDK V1.0.0. and add comments.
- *
- **/
- #include <iostream>
- #include <sstream>
- #include "easyedge/easyedge.h"
- using namespace easyedge;
- int main(int argc, char *argv[]) {
- if (argc != 2) { /* " Usage: demo {model_dir}." */
- std::cerr << "Usage: demo {model_dir}." << std::endl;
- exit(-1);
- }
-
- cv::VideoCapture capture("/dev/video2"); /* camera */
- capture.set(cv::CAP_PROP_FRAME_WIDTH, 1280);
- capture.set(cv::CAP_PROP_FRAME_HEIGHT, 720);
- capture.set(cv::CAP_PROP_FPS, 30);
- cv::Mat img;
- capture.read(img);
-
- EdgePredictorConfig config; /* use EdgePredictorConfig in SDK V1.0.0 instead of EdgePredictorConfig in SDK V0.5 and below. */
- config.model_dir = argv[1];
- global_controller()->set_licence_key("set your owner licence_key"); /* set your owner licence_key */
- EdgeLogConfig log_config;
- log_config.enable_debug = false;
- global_controller()->set_log_config(log_config);
- auto predictor = global_controller()->CreateEdgePredictor<EdgePredictorConfig>(config);
- if (predictor->init() != EDGE_OK) {
- std::cerr << "predictor initial ERROR.please check again." << std::endl;
- exit(-2);
- }
- std::vector<EdgeResultData> result; /* predict result <result:temp not use> <result2:predict result> <result_set_zero:use to set zero>*/
- std::vector<EdgeResultData> result2;
- std::vector<EdgeResultData> result_set_zero;
- while(1)
- {
- capture.read(img); /* grab one frame image */
- result2 = result_set_zero; /* set result to clean */
- predictor->infer(img, result2); /* predict */
- for (auto &v : result2) {
- if (v.prob < 0.2) { /* set the model's threshold */
- continue;
- }
- std::cout << v.index << ", " << v.label << ", p:" << v.prob; /* print result to console */
- if (predictor->model_kind() == EdgeModelKind::kObjectDetection) {
- std::cout << " loc: "
- << v.x1 << ", " << v.y1 << ", " << v.x2 << ", " << v.y2;
- auto p1 = cv::Point(static_cast<int>(v.x1 * img.cols),
- static_cast<int>(v.y1 * img.rows));
- auto p2 = cv::Point(static_cast<int>(v.x2 * img.cols),
- static_cast<int>((v.y2) * img.rows));
- cv::rectangle(img, p1, p2, RED, 3); /* rect the object */
- cv::putText(img, v.label, p1, cv::FONT_HERSHEY_PLAIN, 3, BLUE, 4); /* lable the object */
- }
- std::cout << std::endl;
- }
- std::cout << "Done" << std::endl;
- cv::imshow("MYIR FZ3 baidu brain board. DEMO.", img); /* show the predict image */
- if(cv::waitKey(1)==27) break; /* enter the "ESC" key to exit this program */
- }
- capture.release(); /* prepare to exit. */
- cv::destroyWindow("MYIR FZ3 baidu brain board. DEMO.");
- return 0;
- }
复制代码
|
|