SvpSampleReadAllSrcImg介绍:
输入参数:
1. stDetParam.fpSrc:图像路径列表
2. stDetParam.astSrc:
3. stDetParam.stModel.astSeg[0].u16SrcNum:输入的图像数目,读入时会依次读取
4. imgNameRecoder:
//读取所有图像
HI_S32 SvpSampleReadAllSrcImg(FILE *afp[], SVP_SRC_BLOB_S astSrcBlobs[],
HI_U32 u32SrcNum, vector<SVP_SAMPLE_FILE_NAME_PAIR>& imgNameRecoder)
{
HI_S32 s32Ret = HI_SUCCESS;
imgNameRecoder.clear();
for (HI_U32 j = 0; j < u32SrcNum; j++)//依次读取张图像
{
vector<SVP_SAMPLE_FILE_NAME_PAIR> imgNameRecoder_temp;
if (astSrcBlobs[j].enType >= 0 && astSrcBlobs[j].enType < SVP_BLOB_TYPE_BUTT)
{
FILE *fp = afp[j];
//
s32Ret = SvpSampleImgReadFromImglist(fp, &astSrcBlobs[j], 0, imgNameRecoder_temp);
CHECK_EXP_RET(HI_SUCCESS != s32Ret, s32Ret, "SvpSampleImgReadFromImglist failed");
}
/* get image name only from src[0] image list */
if (0 == j) {
imgNameRecoder = imgNameRecoder_temp;
}
}
return s32Ret;
}
可见其中调用了SvpSampleImgReadFromImglist函数:作用读取图像
HI_S32 SvpSampleImgReadFromImglist(FILE *fp, SVP_BLOB_S *pstBlob,
HI_U32 u32StartLine, vector<SVP_SAMPLE_FILE_NAME_PAIR>& imgNameRecoder)
{
CHECK_EXP_RET(!fp, HI_ERR_SVP_NNIE_NULL_PTR, "fp is null");
CHECK_EXP_RET(!pstBlob, HI_ERR_SVP_NNIE_NULL_PTR, "pstBlob is null");
HI_S32 s32Ret = HI_SUCCESS;
fseek(fp, 0, SEEK_SET);
for (HI_U32 i = 0; i < u32StartLine; i++) {
HI_CHAR aszImg[SVP_SAMPLE_MAX_PATH + 1] = { '\0' };
CHECK_EXP_RET(NULL == aszImg, HI_ERR_SVP_NNIE_NULL_PTR, "aszImg nullptr error!");
s32Ret = SvpSampleReadLine(fp, aszImg, SVP_SAMPLE_MAX_PATH);
CHECK_EXP_RET(HI_SUCCESS != s32Ret, s32Ret, "SvpSampleReadLine ret = %d err", s32Ret);
}
s32Ret = s_SvpSampleImgRead(fp, pstBlob, u32StartLine, imgNameRecoder);
CHECK_EXP_RET(HI_SUCCESS != s32Ret, s32Ret, "s_SvpSampleImgRead ret = %d err", s32Ret);
return s32Ret;
}
最后通过s_SvpSampleImgRead()函数调用opencv读取图像:
static HI_S32 s_SvpSampleImgRead(FILE *fp, SVP_BLOB_S *pstBlob,
HI_U32 u32StartLine, vector<SVP_SAMPLE_FILE_NAME_PAIR>& imgNameRecoder)
{
HI_S32 s32Ret = HI_SUCCESS;
HI_U8 *pu8Ptr = (HI_U8*)pstBlob->u64VirAddr; // blob start addr and help record in num dim
for (HI_U32 i = u32StartLine, j = 0; j < pstBlob->u32Num; i++, j++)
{
HI_CHAR aszImg[SVP_SAMPLE_MAX_PATH + 1] = { '\0' };
CHECK_EXP_RET(NULL == aszImg, HI_ERR_SVP_NNIE_NULL_PTR, "aszImg nullptr error!");
s32Ret = s_SvpSampleReadLineFromImageList(fp, aszImg);
CHECK_EXP_RET(HI_SUCCESS != s32Ret, s32Ret, "s_SvpSampleImgPathRead failed in line(%d) num(%d)!", i, j);
SVP_SAMPLE_FILE_NAME_PAIR filename = SvpSampleGetFileNameFromPath(string(aszImg));
imgNameRecoder.push_back(filename);
/***************************** use OpenCV ******************************/
#ifdef USE_OPENCV
// convert jpeg/png/bmp to raw u8 by OpenCV
std::string strSuffix = filename.second;
transform(strSuffix.begin(), strSuffix.end(), strSuffix.begin(), ::tolower);
if (strSuffix == "jpg" || strSuffix == "jpeg" || strSuffix == "png" || strSuffix == "bmp")
{
s32Ret = svpsample_utils_cv::SVPUtils_ReadImage(aszImg, pstBlob, &pu8Ptr);
CHECK_EXP_RET(HI_SUCCESS != s32Ret, s32Ret, "SVPUtils_ReadImage error, ret = %d", s32Ret);
}
else
#endif
{
s32Ret = SvpSampleImgReadRaw(aszImg, pstBlob, &pu8Ptr);
CHECK_EXP_RET(HI_SUCCESS != s32Ret, s32Ret, "SvpSampleImgReadRaw error, ret = %d", s32Ret);
}
}
return s32Ret;
}
结构体介绍:SVP_BLOB_S
typedef SVP_BLOB_S SVP_SRC_BLOB_S;
typedef SVP_BLOB_S SVP_DST_BLOB_S;
在caffe中,blob的结构shape如下所示:
Image/FeatureMap : N*C*H*W
FC(normal vector) : N*C