File size: 1,479 Bytes
ce7fc72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/* Copyright (c) 2026 Eoin Jordan
 * SPDX-License-Identifier: Apache-2.0
 *
 * Runs the firmware's decoder (src/pose_decode.h) on a PC. Reads one network
 * output from a file written by test_pose_decode.py and prints the 17
 * keypoints, for that script to compare with the Python decoder.
 *
 * File: int32 is_int8, int32 channels_last, float scale, int32 zero_point,
 * then 51 * 144 values, float32 or int8.
 */
#include <cstdio>
#include <cstdlib>
#include <vector>

#include "pose_decode.h"

int main(int argc, char **argv)
{
	if (argc != 2) {
		return 2;
	}
	FILE *f = fopen(argv[1], "rb");
	if (f == nullptr) {
		return 2;
	}
	int32_t is_int8 = 0, channels_last = 0, zero_point = 0;
	float scale = 0.f;
	if (fread(&is_int8, 4, 1, f) != 1 || fread(&channels_last, 4, 1, f) != 1 ||
	    fread(&scale, 4, 1, f) != 1 || fread(&zero_point, 4, 1, f) != 1) {
		return 2;
	}
	const size_t item = is_int8 ? 1 : sizeof(float);
	std::vector<unsigned char> data(pose::kOutputs * item);
	if (fread(data.data(), item, pose::kOutputs, f) != static_cast<size_t>(pose::kOutputs)) {
		return 2;
	}
	fclose(f);

	const pose::Output out = {data.data(), is_int8 != 0, channels_last != 0, scale, zero_point};
	pose::Keypoint k[pose::kKeypoints];
	pose::decode(out, k);
	printf("%d\n", pose::found(k));
	for (int i = 0; i < pose::kKeypoints; ++i) {
		printf("%.6f %.6f %.6f\n", static_cast<double>(k[i].x), static_cast<double>(k[i].y),
		       static_cast<double>(k[i].heat));
	}
	return 0;
}