//
|
// Created by Scheaven on 2019/12/27.
|
//
|
#include <torch/script.h> // One-stop header.
|
#include <iostream>
|
#include <memory>
|
#include <vector>
|
#include <string>
|
#include <opencv2/core/core.hpp>
|
#include <opencv2/highgui/highgui.hpp>
|
#include "opencv2/imgproc/imgproc.hpp"
|
#include "opencv2/opencv.hpp"
|
#include "opencv2/videoio.hpp"
|
#include "reid_feature.h"
|
|
|
using namespace std;
|
//using namespace cv;
|
|
int main(int argc, const char* argv[]) {
|
// if (argc != 2) {
|
// std::cerr << "usage: reid-app <image path>\n";;
|
// return -1;
|
// }
|
|
// torch::jit::script::Module module;
|
// char cam_id = 'A';
|
// ReID_Tracker Tracker;
|
|
|
|
/*初始化*/
|
int gpu_id = 0;
|
ReID_Feature R_Feater;
|
bool n_flog = R_Feater.ReID_init(0);
|
// ReID_Feature R_Feater(gpu_id);
|
|
/*opencv加载图片信息*/
|
cv::Mat human_img = cv::imread("./03.jpg");
|
cv::Mat human_img2 = cv::imread("./01.jpg");
|
if (human_img.data == nullptr)
|
{
|
cerr<<"===图片文件不存在"<<endl;
|
return 0;
|
}else
|
{
|
//cv::namedWindow("Display", CV_WINDOW_AUTOSIZE);
|
try {
|
float pFeature1[2048];
|
/*转义图片信息格式*/
|
cv::cvtColor(human_img, human_img, cv::COLOR_RGB2BGR);
|
human_img.convertTo(human_img, CV_32FC3, 1.0f / 255.0f);
|
bool ex_flag1 = R_Feater.ReID_extractor(human_img.data, pFeature1);
|
// for (int k = 0; k < 20; ++k) {
|
// cout << "-----11111111111------" <<pFeature1[k+2000]<< endl;
|
// }
|
|
float pFeature2[2048];
|
cv::cvtColor(human_img2, human_img2, cv::COLOR_RGB2BGR);
|
human_img2.convertTo(human_img2, CV_32FC3, 1.0f / 255.0f);
|
bool ex_flag2 = R_Feater.ReID_extractor(human_img2.data, pFeature2);
|
// for (int k = 0; k < 20; ++k) {
|
// cout << "-----2222222222------" <<pFeature2[k+2000]<< endl;
|
// }
|
|
/*计算相似度*/
|
cout << "--attention_distance human-" << endl;
|
float result = R_Feater.ReID_Compare(pFeature1, pFeature2);
|
|
// Tracker.storager(1,human_img);
|
}
|
catch (const c10::Error& e) {
|
std::cerr << "error loading the model\n";
|
return -1;
|
}
|
|
std::cout << "ok\n";
|
//cout<< human_img <<endl;
|
//cv::imshow("0909",human_img);
|
//cv::waitKey(0);
|
}
|
|
}
|