c++人群计数SaCNN代码应用实现

概述

SaCNN原理可自行参考论文,它算是目前人群计数相对来说较好的几个模型之一,后期会写有关CSRNET人群计数,本文主要是用c++对模型扩展,进行实际测试,由于是很早之前所作,懒得再次测试,只贴部分代码,完整部分可依据链接下载SaCNN完整代码
2019-12-18添加:
shanghaiTech-PartB训练好的模型

代码实现

#ifndef FEATUREEXTRACT_H_
#define FEATUREEXTRACT_H_
#include <caffe/caffe.hpp>
#define USE_OPENCV
#ifdef USE_OPENCV
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif  // USE_OPENCV
#include <algorithm>
#include <iosfwd>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <pthread.h>
#ifdef USE_OPENCV
using namespace caffe;  // NOLINT(build/namespaces)
using std::string;
using namespace std;
/* Pair (label, confidence) representing a prediction. */

class FeatureExtract {
 public:
  FeatureExtract(const string& model_file,
             const string& trained_file);
	int extractFeature(cv::Mat img,float &cnt);
  
 // std::vector<Prediction> Classify(const cv::Mat& img, int N = 5);

 private:
 // void SetMean(const string& mean_file);
	pthread_mutex_t net_lock;

	int Predict(const cv::Mat& img,float *output);
  void WrapInputLayer(std::vector<cv::Mat>* input_channels);

  void Preprocess(const cv::Mat& img,
                  std::vector<cv::Mat>* input_channels);

 private:
	
  boost::shared_ptr<Net<float> > net_;
  cv::Size input_geometry_;
  int num_channels_;
  //std::vector<string> labels_;
};

float mycosine(float* arrayA,float* arrayB,int length);

#else
/*
int main(int argc, char** argv) {
  LOG(FATAL) << "This example requires OpenCV; compile with USE_OPENCV.";
}*/
#endif  // USE_OPENCV
#endif

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值