python代码转化成c++代码_这段C++语言的代码如何转换成python语言的代码?

#include#include#include#includeconstcv::SizeMAX_DETECT_SIZE=cv::Size(100,200);constintM...

#include

#include

#include

#include

const cv::Size MAX_DETECT_SIZE = cv::Size(100, 200);

const int MAX_MISS_FRAME = 10;

const double MIN_NEW_DETECT_INTERSECTION_RATE = 0.5;

class MyTracker {

private:

static int next_id;

int id;

int n_miss_frame = 0;

cv::Rect2d rect;

cv::Ptr<:tracker> cv_tracker;

public:

MyTracker(const cv::Mat& _frame, const cv::Rect2d& _rect)

: id(next_id++), rect(_rect) {

cv_tracker = cv::Tracker::create("BOOSTING"); // or "MIL"

cv_tracker->init(_frame, _rect);

}

bool update(const cv::Mat& _frame){

n_miss_frame++;

return cv_tracker->update(_frame, rect) && n_miss_frame < MAX_MISS_FRAME;

}

bool registerNewDetect(const cv::Rect2d& _new_detect){

double intersection_rate = 1.0 * (_new_detect & rect).area() / (_new_detect | rect).area();

bool is_registered = intersection_rate > MIN_NEW_DETECT_INTERSECTION_RATE;

if (is_registered) n_miss_frame = 0;

return is_registered;

}

void draw(cv::Mat& _image) const{

cv::rectangle(_image, rect, cv::Scalar(255, 0, 0), 2, 1);

cv::putText(_image, cv::format("%03d", id), cv::Point(rect.x + 5, rect.y + 17),

cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(255,0,0), 1, CV_AA);

}

};

int MyTracker::next_id = 0;

int main(int argc, char* argv[]){

if(argc != 2){

std::cout << "usage: " << argv[0] << " videodir" << std::endl;

exit(1);

}

namespace fs = boost::filesystem;

std::vector<:string> frame_paths;

for(auto it = fs::directory_iterator(argv[1]); it != fs::directory_iterator(); ++it){

frame_paths.push_back(it->path().string());

}

cv::HOGDescriptor detector;

detector.setSVMDetector(cv::HOGDescriptor::getDefaultPeopleDetector());

std::vector trackers;

for (auto& frame_path : frame_paths){

std::cout << "frame : " << frame_path << std::endl;

cv::Mat frame = cv::imread(frame_path);

std::vector<:rect> detections;

detector.detectMultiScale(frame, detections);

for (auto t_it = trackers.begin(); t_it != trackers.end();){

t_it = (t_it->update(frame)) ? std::next(t_it) : trackers.erase(t_it);

}

for(auto& d_rect : detections){

if (d_rect.size().area() > MAX_DETECT_SIZE.area()) continue;

bool is_exsisting = std::any_of(trackers.begin(), trackers.end(),

[&d_rect](MyTracker& t){return t.registerNewDetect(d_rect);});

if(!is_exsisting) trackers.push_back(MyTracker(frame, d_rect));

}

cv::Mat image = frame.clone();

for(auto& t : trackers) t.draw(image);

for(auto& d_rect : detections) cv::rectangle(image, d_rect, cv::Scalar(0, 255, 0), 2, 1);

cv::imshow("demo", image);

cv::waitKey(1);

}

return 0;

}

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值