xuepengqiang
2020-01-06 bf3d2d5e30e4b5c3a44d86aa5a9a2d739df55bd7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// 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);
    }
 
}