/* ThermalSDK harness v2: capture official IR frames, save several for * analysis. The callback delivers w x h x 3 RGB. */ #define _WIN32_WINNT 0x0601 #include #include #include #include typedef void (CALLBACK *INewIRFrame)(const unsigned char *, int, int, int); typedef void (CALLBACK *INewDistance)(float); typedef void (CALLBACK *IDistanceError)(); typedef bool (CALLBACK *fn_Start_t)(void); typedef void (CALLBACK *fn_Stop_t)(void); typedef void (CALLBACK *fn_SetNewIRFrameDelegate_t)(INewIRFrame); typedef void (CALLBACK *fn_SetNewDistanceDelegate_t)(INewDistance); typedef void (CALLBACK *fn_SetDistanceError_t)(IDistanceError); typedef void (CALLBACK *fn_ReadTemperatureAtPoint_t)(int, int, unsigned char *); typedef void (CALLBACK *fn_SetTempBoundary_t)(double, double, double); typedef void (CALLBACK *fn_SetUnitMode_t)(int); static int g_saved; static FILE *g_meta; static void CALLBACK onIR(const unsigned char *buf, int w, int h, int ch) { if (g_saved < 10 && buf) { char path[128]; snprintf(path, sizeof(path), "official_ir_%02d.rgb", g_saved); FILE *f = fopen(path, "wb"); if (f) { fwrite(buf, 1, (size_t)w * h * ch, f); fclose(f); } fprintf(g_meta, "%d %d %d %d\n", g_saved, w, h, ch); fflush(g_meta); g_saved++; } } static void CALLBACK onDist(float d) { (void)d; } static void CALLBACK onDistErr() {} int main(void) { SetDllDirectoryA("C:\\Project\\MAG160C\\IR_Camera_SDK-1.0.1\\windows\\windows\\app"); HMODULE h = LoadLibraryA("ThermalSDK.dll"); if (!h) { printf("load fail %lu\n", GetLastError()); return 1; } fn_Start_t T_Start = (fn_Start_t)GetProcAddress(h, "Start"); fn_Stop_t T_Stop = (fn_Stop_t)GetProcAddress(h, "Stop"); fn_SetNewIRFrameDelegate_t T_Set = (fn_SetNewIRFrameDelegate_t)GetProcAddress(h, "SetNewIRFrameDelegate"); fn_SetNewDistanceDelegate_t T_Dist = (fn_SetNewDistanceDelegate_t)GetProcAddress(h, "SetNewDistanceDelegate"); fn_SetDistanceError_t T_Err = (fn_SetDistanceError_t)GetProcAddress(h, "SetDistanceError"); fn_ReadTemperatureAtPoint_t T_Temp = (fn_ReadTemperatureAtPoint_t)GetProcAddress(h, "ReadTemperatureAtPoint"); fn_SetTempBoundary_t T_Bound = (fn_SetTempBoundary_t)GetProcAddress(h, "SetTempBoundary"); fn_SetUnitMode_t T_Unit = (fn_SetUnitMode_t)GetProcAddress(h, "SetUnitMode"); if (!T_Start || !T_Set || !T_Temp) { printf("missing exports\n"); return 2; } g_meta = fopen("official_meta.txt", "w"); T_Unit(0); T_Bound(30.0, 44.0, 37.0); T_Set(T_Bound ? onIR : onIR); T_Dist(onDist); T_Err(onDistErr); T_Set(onIR); printf("Start...\n"); fflush(stdout); BOOL ok = T_Start(); printf("Start=%d\n", ok); fflush(stdout); /* wait and read temps at several points */ DWORD t0 = GetTickCount(); int npoints = 0; while (g_saved < 8 && GetTickCount() - t0 < 15000) { Sleep(200); if ((GetTickCount() - t0) > 3000 && npoints < 6) { int x = 40 + (npoints % 3) * 40, y = 40 + (npoints / 3) * 40; unsigned char res[64] = {0}; T_Temp(x, y, res); printf("temp(%d,%d): ", x, y); for (int i = 0; i < 24; ++i) printf("%02x ", res[i]); printf("\n"); npoints++; } } printf("saved %d frames\n", g_saved); if (g_meta) fclose(g_meta); T_Stop(); printf("done\n"); return 0; }