int main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, "usage: %s <cfg fname>\n", argv[0]); return -1; } const char *fname = argv[1]; struct sockaddr_in addr; int fd; int st; if ((fd=socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("socket"); exit(-1); } memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(MULTICAST_ADDR); addr.sin_port = htons(PORT); detect_t *det = det_open(fname); while (true) { char c; const char *message = det_detect(det); printf("###### aims %s\n", message); std::string s(message); int len = s.size(); if (s[len-3] == '[') continue; if ((st = sendto(fd, message, strlen(message), 0, (const sockaddr*)&addr, sizeof(addr))) < 0) { perror("sendto"); printf("error %s\n", strerror(errno)); usleep(100 * 1000); } usleep(100 * 1000); } }
int main(int argc, char const *argv[]) { VI_EXT_CHN_ATTR_S stExtChnAttr; VB_BLK hBlock; VB_POOL hPool = VB_INVALID_POOLID; HI_S32 s32Ret = HI_SUCCESS; HI_U32 u32BlkSize, u32DstBlkSize; VIDEO_FRAME_INFO_S FrameInfo; IVE_HANDLE IveHandle; IVE_SRC_IMAGE_S stSrc; IVE_DST_IMAGE_S stDst; IVE_CSC_CTRL_S stCscCtrl; HI_BOOL bInstant = HI_TRUE; HI_BOOL bFinish; IplImage *iplImage; FILE *fp,*fp2; int k=1; #if 0 memset(&stVbConf, 0, sizeof(VB_CONF_S)); stVbConf.u32MaxPoolCnt = 128; SAMPLE_COMM_VI_GetSizeBySensor(&enSize); u32BlkSize = SAMPLE_COMM_SYS_CalcPicVbBlkSize(gs_enNorm, enSize, SAMPLE_PIXEL_FORMAT, SAMPLE_SYS_ALIGN_WIDTH); stVbConf.astCommPool[0].u32BlkSize = u32BlkSize; stVbConf.astCommPool[0].u32BlkCnt = 12; s32Ret = SAMPLE_COMM_SYS_Init(&stVbConf); if (HI_SUCCESS != s32Ret) { printf("system init failed with err code %#x!\n", s32Ret ); } stViConfig.enViMode = SENSOR_TYPE; stViConfig.enRotate = ROTATE_NONE; stViConfig.enNorm = VIDEO_ENCODING_MODE_AUTO; stViConfig.enViChnSet = VI_CHN_SET_NORMAL; s32Ret = SAMPLE_COMM_VI_StartVi(&stViConfig); if (HI_SUCCESS != s32Ret) { printf("start vi failed with err code %#x!\n", s32Ret); // goto END_1; } #endif iplImage = cvCreateImageHeader(cvSize(WIDTH,HEIGHT), IPL_DEPTH_8U, 3); stExtChnAttr.enPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420; stExtChnAttr.s32BindChn = ViChn; stExtChnAttr.stDestSize.u32Width = WIDTH; stExtChnAttr.stDestSize.u32Height = HEIGHT; stExtChnAttr.s32DstFrameRate = -1; stExtChnAttr.s32SrcFrameRate = -1; stExtChnAttr.enCompressMode = COMPRESS_MODE_NONE; HI_MPI_VI_DisableChn(ExtChn); s32Ret = HI_MPI_VI_SetExtChnAttr(ExtChn, &stExtChnAttr); if (HI_SUCCESS != s32Ret) { printf("HI_MPI_VI_SetExtChnAttr failed with err code %#x\n", s32Ret); return -1; } s32Ret = HI_MPI_VI_SetFrameDepth(ExtChn, 1); if (HI_SUCCESS != s32Ret) { printf("HI_MPI_VI_SetFrameDepth failed with err code %#x\n", s32Ret); return -1; } stSrc.enType = IVE_IMAGE_TYPE_YUV420SP; //stDst.enType = IVE_IMAGE_TYPE_U8C3_PLANAR; stDst.enType = IVE_IMAGE_TYPE_U8C3_PACKAGE; stCscCtrl.enMode = IVE_CSC_MODE_PIC_BT709_YUV2RGB; #if 1 s32Ret = HI_MPI_VI_EnableChn(ExtChn); if (HI_SUCCESS != s32Ret) { printf("HI_MPI_VI_EnableChn failed with err code %#x\n", s32Ret); return -1; } #endif printf("begin\n"); det_t *pdet = det_open("bd_detect_trace.config"); while(k) { s32Ret = HI_MPI_VI_GetFrame(ExtChn, &FrameInfo, -1); if(HI_SUCCESS != s32Ret) { printf("HI_MPI_VI_GetFrame failed with err code %#x!\n",s32Ret); } printf("get frame!\n"); u32DstBlkSize = FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height * 3; s32Ret = HI_MPI_SYS_MmzAlloc_Cached(&stDst.u32PhyAddr[0],(void**) &stDst.pu8VirAddr[0], "user", HI_NULL, u32DstBlkSize); HI_MPI_SYS_MmzFlushCache(stDst.u32PhyAddr[0], (void *)stDst.pu8VirAddr[0], u32DstBlkSize); #if 0 stDst.u32PhyAddr[1] = stDst.u32PhyAddr[0] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height; stDst.u32PhyAddr[2] = stDst.u32PhyAddr[1] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height; stDst.pu8VirAddr[0] = (HI_U8*) HI_MPI_SYS_Mmap(stDst.u32PhyAddr[0], u32DstBlkSize); stDst.pu8VirAddr[1] = stDst.pu8VirAddr[0] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height; stDst.pu8VirAddr[2] = stDst.pu8VirAddr[1] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height; stDst.u16Stride[0] = FrameInfo.stVFrame.u32Stride[0]; stDst.u16Stride[1] = FrameInfo.stVFrame.u32Stride[0]; stDst.u16Stride[2] = FrameInfo.stVFrame.u32Stride[0]; stDst.u16Width = FrameInfo.stVFrame.u32Width; stDst.u16Height = FrameInfo.stVFrame.u32Height; #endif #if 1 stDst.pu8VirAddr[0] = (HI_U8*) HI_MPI_SYS_Mmap(stDst.u32PhyAddr[0], u32DstBlkSize); stDst.u16Stride[0] = FrameInfo.stVFrame.u32Stride[0]; stDst.u16Width = FrameInfo.stVFrame.u32Width; stDst.u16Height = FrameInfo.stVFrame.u32Height; #endif stSrc.u32PhyAddr[0] = FrameInfo.stVFrame.u32PhyAddr[0]; stSrc.u32PhyAddr[1] = FrameInfo.stVFrame.u32PhyAddr[1]; stSrc.u32PhyAddr[2] = FrameInfo.stVFrame.u32PhyAddr[2]; stSrc.pu8VirAddr[0] = (HI_U8*)HI_MPI_SYS_Mmap(FrameInfo.stVFrame.u32PhyAddr[0], u32DstBlkSize / 2); stSrc.pu8VirAddr[1] = stSrc.pu8VirAddr[0] + FrameInfo.stVFrame.u32Stride[0] * FrameInfo.stVFrame.u32Height; stSrc.pu8VirAddr[2] = stSrc.pu8VirAddr[1] + 1; stSrc.u16Stride[1] = FrameInfo.stVFrame.u32Stride[0]; stSrc.u16Stride[0] = FrameInfo.stVFrame.u32Stride[0]; stSrc.u16Stride[2] = 0; stSrc.u16Width = FrameInfo.stVFrame.u32Width; stSrc.u16Height = FrameInfo.stVFrame.u32Height; #if 0 for(k = 0; k < 720 * 576 * 3 / 2;k++) *(stSrc.pu8VirAddr[0] + k) = 130; k = 0; #endif s32Ret = HI_MPI_IVE_CSC(&IveHandle, &stSrc, &stDst, &stCscCtrl, bInstant); if(s32Ret != HI_SUCCESS) { printf("HI_MPI_IVE_CSC failed with error code %#x\n",s32Ret); continue; } s32Ret = HI_MPI_IVE_Query(IveHandle, &bFinish, HI_TRUE); if(s32Ret != HI_SUCCESS) { printf("HI_MPI_IVE_Query failed with error code %#x\n",s32Ret); continue; } #if 0 fp = fopen("image.rgb","wb"); fwrite(stDst.pu8VirAddr[0], WIDTH * HEIGHT * 3, 1, fp); fclose(fp); fp2 = fopen("image2.yuv","wb"); fwrite(stSrc.pu8VirAddr[0], WIDTH * HEIGHT * 3 / 2, 1, fp2); fclose(fp2); #endif //printf("u16Width:%d,u16Height:%d\n",stDst.u16Width,stDst.u16Height); //printf("widthStep:%d\n",iplImage->widthStep); //cvSetData(iplImage, stDst.pu8VirAddr[0], iplImage->widthStep); //cvSaveImage("saveImage.jpg",iplImage); char *str = det_detect(pdet, HEIGHT, WIDTH, (char *)stDst.pu8VirAddr[0]); printf("%s\n",str); HI_MPI_SYS_Munmap(stDst.pu8VirAddr[0], u32DstBlkSize); HI_MPI_SYS_Munmap(stSrc.pu8VirAddr[0], u32DstBlkSize / 2); HI_MPI_SYS_MmzFree(stDst.u32PhyAddr[0], NULL); HI_MPI_VI_ReleaseFrame(ExtChn, &FrameInfo); } det_close(pdet); }