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
| //
| // Created by Scheaven on 2020/1/3.
| //
|
| #include "reid_utils.h"
|
| //import torch
| //
| //a=torch.Tensor([[1,2,3],[4,5,6]])
| //b=torch.Tensor([[7,8,9],[10,11,12]])
| //d=torch.stack( (a,b) ,dim = 1)
| //
| //print(d)
|
| //template<typename T>
| //unsigned char * ReID_Utils::T2bytes(T u)
| //{
| // int n = sizeof(T);
| // unsigned char* b = new unsigned char[n];
| // memcpy(b, &u, n);
| // return b;
| //}
| //
| //template<typename T>
| //T ReID_Utils::bytes2T(unsigned char *bytes)
| //{
| // T res = 0;
| // int n = sizeof(T);
| // memcpy(&res, bytes, n);
| // return res;
| //}
|
| unsigned char * ReID_Utils::T2bytes(float u)
| {
| int n = sizeof(u);
| unsigned char* b = new unsigned char[n];
| memcpy(b, &u, n);
| return b;
| }
|
| float ReID_Utils::bytes2T(unsigned char *bytes)
| {
| float res = 0;
| int n = sizeof(res);
| memcpy(&res, bytes, n);
| return res;
| }
|
| void *ReID_Utils::normalize(unsigned char *vsrc, int w, int h, int chan){
| float *data = (float*)malloc(h*w*chan*sizeof(float));
| int size = w*h;
| int size2 = size*2;
|
| unsigned char *srcData = (unsigned char*)vsrc;
|
| for(int i = 0;i<size;i++){
| *(data) = *(srcData + 2) /255.0f;
| *(data+size) = *(srcData + 1) /255.0f;
| *(data+size2) = *(srcData) /255.0f;
| data++;
| srcData+=3;
| }
|
| return data;
| }
|
|