/*============ ImageInjector : Inject ============== */
int Device1_Process0_Source_Inject_Mode_Id = Fg_getParameterIdByName(fg, "Device1_Process0_Source_Inject_Mode");
FG_CHECK(Device1_Process0_Source_Inject_Mode_Id);
unsigned int Device1_Process0_Source_Inject_Mode;
Device1_Process0_Source_Inject_Mode = InjectMode::Inject;
FG_CHECK(Fg_setParameterWithType(fg, Device1_Process0_Source_Inject_Mode_Id, Device1_Process0_Source_Inject_Mode, 0));
// ---------------------------------------------------------------------------
// Frame Grabber: Grab images
// ---------------------------------------------------------------------------
int Device1_Process0_Source_Inject_ReadyForInjection_Id = Fg_getParameterIdByName(fg, "Device1_Process0_Source_Inject_ReadyForInjection");
FG_CHECK(Device1_Process0_Source_Inject_ReadyForInjection_Id);
unsigned int ReadyForInjection = -1;
int Device1_Process0_Source_Inject_ImageFile_Id = Fg_getParameterIdByName(fg, "Device1_Process0_Source_Inject_ImageFile");
FG_CHECK(Device1_Process0_Source_Inject_ImageFile_Id);
const char * Inject_ImageFileName = "unset";
int Device1_Process0_Source_Inject_InjectFromFile_Id = Fg_getParameterIdByName(fg, "Device1_Process0_Source_Inject_InjectFromFile");
FG_CHECK(Device1_Process0_Source_Inject_InjectFromFile_Id);
// within the acquisition loop, sorry for using fprintf :-)
fprintf(stderr, "Waiting for Injection ready ..");
FG_CHECK(Fg_getParameterWithType(fg, Device1_Process0_Source_Inject_ReadyForInjection_Id, &ReadyForInjection, 0));
} while (ReadyForInjection != InjectReady::yes);
auto fn = filename.string();
Inject_ImageFileName = fn.c_str();
fprintf(stderr, "Uploading %s ", Inject_ImageFileName);
FG_CHECK(Fg_setParameterWithType(fg, Device1_Process0_Source_Inject_ImageFile_Id, Inject_ImageFileName, 0));
fprintf(stderr, "...", Inject_ImageFileName);
int Device1_Process0_Source_Inject_InjectFromFile = InjectReady::yes;
FG_CHECK(Fg_setParameterWithType(fg, Device1_Process0_Source_Inject_InjectFromFile_Id, Device1_Process0_Source_Inject_InjectFromFile, 0));
fprintf(stderr, " OK\n");
fprintf(stderr, "Sending ... ", Inject_ImageFileName);
Device1_Process0_Source_RUN_Mode = SetSignalStatus::Pulse;
FG_CHECK(Fg_setParameterWithType(fg, Device1_Process0_Source_RUN_Mode_Id, Device1_Process0_Source_RUN_Mode, 0));
int timeout_secs = 1; // because of file upload and start requiring time
frameNo0 = Fg_getLastPicNumberBlockingEx(fg, frameNo0 + 1, 0, timeout_secs, pmem0);
void *iPtr0 = Fg_getImagePtrEx(fg, frameNo0, 0, pmem0);
// save file nicely, suing openCV function for save. SiSo IO will work similar
cv::Mat result(height0, width0, CV_8UC1, iPtr0);
auto targetFilename = filename.filename();
auto targetPath = filename.parent_path().string() + "/Runtime/";
auto target = targetPath + targetFilename.string();
cv::imwrite(target, result);