I’m using a Hikvision camera with openCV with the purpose of getting a streaming of the camera in a window on my pc. I started using a SDK from HIKVISION (here is the link: https://www.hikvision.com/es/support/download/sdk/device-network-sdk--for-linux-64-bit-/) for getting some examples and start practicing. I used the psdatacall_demo because it was the most similar demo to my objective. This file records a video and saves it in a .dat format.
Below I paste the SDK function where the script saves the buffer in the .dat file. My goal is to change this approach to a real-time display window of the camera video using the OpenCV library.
void PsDataCallBack(LONG lRealHandle, DWORD dwDataType,BYTE *pPacketBuffer,DWORD nPacketSize, void* pUser)
{
if (dwDataType == NET_DVR_SYSHEAD)
{
g_pFile = fopen("../record/ps.dat", "wb");
if (g_pFile == NULL)
{
printf("CreateFileHead fail\n");
return;
}
fwrite(pPacketBuffer, sizeof(unsigned char), nPacketSize, g_pFile);
printf("write head len=%d\n", nPacketSize);
}
else
{
if(g_pFile != NULL)
{
fwrite(pPacketBuffer, sizeof(unsigned char), nPacketSize, g_pFile);
printf("write data len=%d\n", nPacketSize);
//cv::Mat frame = cv::imdecode(cv::Mat(240, 320, CV_8UC1, pPacketBuffer), 1);
//cv::imshow("Streaming", frame);
}
}
}
I think that this function is the part of the code that should be changed. I have tried to develop this functionality adding the commented lines above, however it gives me this error:
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.7.0-dev) /path of the src/loadsave.cpp:800: error: (-215:Assertion failed) buf.checkVector(1, CV_8U) > 0 in function 'imdecode_'
Aborted (core dumped)
Could anyone tell me how can I solve this?