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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
VSIDRIVER_API int CamSaveImageSetInC(const int numFrames, char fname[])
{
//Memory Allocation: Image, Temperature, and Header
short *m_buf = new short[camInfo.numPixels*numFrames] ;
float temp;
char Header[120][120];
// My attempt at using Strings/vectors instead of chars
//string* Headers = new string[numFrames];
//vector<string> HeaderVec;
//char ** NewHeader[120] = new char[numFrames];
// Creates an initial header and opens up the files
HRESULT hr = CamStartImageSet(numFrames, fname);
if(hr!=0)
{
CamEndImageSet();
return hr;
}
// Loops through X images and references the function CamGetImage below
for (int n = 0; n < numFrames; n++)
{
HRESULT hr = CamGetImageSet((m_buf + n*camInfo.numPixels), Header[n], &temp);
//HRESULT hr = CamGetImageSet((m_buf + n*camInfo.numPixels), Headers + n*strlen(Headers), &temp);
if (hr!=0)
n=n-1;
camStatus.numCounts = n+1;
}
//Takes image and header sets and writes them to separate files
if (hr == 0)
{
hr = fwrite(m_buf, 2, camInfo.numPixels*numFrames, fp);
hr = fwrite(Header, 2, numFrames*120, Hd);
};
if(m_buf)
delete m_buf;
// Closes the files
return CamEndImageSet();;
}
VSIDRIVER_API int CamGetImageSet(short * m_buf, char Header[], float *tempK)
{
if(!InitSharedMem())
return IDS_INI_MEM_ERROR;
if(!m_pVirtualCam)
return FALSE;
HRESULT hr;
BOOL bReturn = FALSE;
BSTR bstrNextImageBuffer = CComBSTR (m_sSharedMem[IMG_SHARED_MEM].strSharedName).Copy();
BSTR bstrNextInfoBuffer = CComBSTR (m_sSharedMem[INF_SHARED_MEM].strSharedName).Copy();
//example : GetImage(Width, Heigth, Number of subsampling, image shared memory name, image offset, info shared memory name, info offset, image time out, function return)
hr = m_pVirtualCam->GetImage(m_dwPoint, m_dwLine, MODULO, bstrNextImageBuffer, 0, bstrNextInfoBuffer, 0, IMG_TIME_OUT, (ULONG*)&bReturn);
::SysFreeString(bstrNextImageBuffer);
::SysFreeString(bstrNextInfoBuffer);
if(FAILED(hr))
return IDS_SERVER_NOT_RESPONDING;
if(!bReturn)
return IDS_NO_IMAGE;
memcpy(m_buf, m_sSharedMem[IMG_SHARED_MEM].pMemBuffer, (m_dwPoint * m_dwLine) * sizeof(WORD));
// The camera stores all the information in a structure which I then
// pull any of the information out I need
InfoImageStruct* pInfoImage = ((InfoImageStruct*)m_sSharedMem[INF_SHARED_MEM].pMemBuffer);
if(!pInfoImage)
return FALSE;
camInfo.DetectorTemp=pInfoImage->fDetectorTemp;
camInfo.IntegrationTime=pInfoImage->fIntegrationTime;
camInfo.FrameRate= pInfoImage->fFrameRate;
//I have tried using memcpy as well to get the information
//memcpy(Headerss, m_sSharedMem[INF_SHARED_MEM].pMemBuffer, 1000);
// My attempt with using strings and ostringsteam
//ostringstream oss;
//oss << "Preset:" << pInfoImage->wMultiItNumber <<
// "ITime:" << pInfoImage->fIntegrationTime <<
// "ImageTime:" << pInfoImage->qwImageTime;
//Headerss = oss.str();
// Here is how I currently am able to write to Header
sprintf_s(Header, 120, "Preset:%d; ITime:%7.3f; ImageTime:%I64u; Count:%I64u; T:%.1f; T1:%.1f; T2:%.1f; T3:%.1f; T4:%.1f\n",
pInfoImage->wMultiItNumber, //preset
pInfoImage->fIntegrationTime,
pInfoImage->qwImageTime,
pInfoImage->qwImageCounter,
pInfoImage->fDetectorTemp,
pInfoImage->fSensorTemp[0],
pInfoImage->fSensorTemp[1],
pInfoImage->fSensorTemp[2],
pInfoImage->fSensorTemp[3]);
*tempK = camInfo.DetectorTemp;
BOOL pbReturn = FALSE;
return 0;
}
|