#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include "MvCameraControl.h"
void PressEnterToExit(void)
{
int c;
while ( (c = getchar()) != '\n' && c != EOF );
fprintf( stderr, "\nPress enter to exit.\n");
while( getchar() != '\n');
}
{
if (NULL == pstMVDevInfo)
{
printf("The Pointer of pstMVDevInfo is NULL!\n");
return false;
}
{
printf("CurrentIp: %d.%d.%d.%d\n" , nIp1, nIp2, nIp3, nIp4);
}
{
}
else
{
printf("Not support.\n");
}
return true;
}
int main()
{
void* handle = NULL;
unsigned char *
pData = NULL;
unsigned char *pDataForRGB = NULL;
unsigned char *pDataForSaveImage = NULL;
do
{
if (MV_OK != nRet)
{
printf("MV_CC_EnumDevices fail! nRet [%x]\n", nRet);
break;
}
{
{
printf("[device %d]:\n", i);
if (NULL == pDeviceInfo)
{
break;
}
PrintDeviceInfo(pDeviceInfo);
}
}
else
{
printf("Find No Devices!\n");
break;
}
printf("Please Intput camera index: ");
unsigned int nIndex = 0;
scanf("%d", &nIndex);
{
printf("Intput error!\n");
break;
}
if (MV_OK != nRet)
{
printf("MV_CC_CreateHandle fail! nRet [%x]\n", nRet);
break;
}
if (MV_OK != nRet)
{
printf("MV_CC_OpenDevice fail! nRet [%x]\n", nRet);
break;
}
if (
stDeviceList.pDeviceInfo[nIndex]->nTLayerType == MV_GIGE_DEVICE)
{
if (nPacketSize > 0)
{
if(nRet != MV_OK)
{
printf("Warning: Set Packet Size fail nRet [0x%x]!\n", nRet);
}
}
else
{
printf("Warning: Get Packet Size fail nRet [0x%x]!\n", nPacketSize);
}
}
if (MV_OK != nRet)
{
printf("MV_CC_SetTriggerMode fail! nRet [%x]\n", nRet);
break;
}
if (MV_OK != nRet)
{
printf("Get PayloadSize fail! nRet [0x%x]\n", nRet);
break;
}
if (MV_OK != nRet)
{
printf("MV_CC_StartGrabbing fail! nRet [%x]\n", nRet);
break;
}
pData = (
unsigned char *)malloc(
sizeof(
unsigned char) *
stParam.nCurValue);
if (NULL == pData)
{
break;
}
unsigned int nDataSize =
stParam.nCurValue;
if (nRet == MV_OK)
{
printf("Now you GetOneFrame, Width[%d], Height[%d], nFrameNum[%d]\n\n",
printf("input 0 to do nothing, 1 to convert RGB, 2 to save as BMP\n");
int nInput = 0;
scanf("%d", &nInput);
switch (nInput)
{
case 0:
{
break;
}
case 1:
{
pDataForRGB = (
unsigned char*)malloc(stImageInfo.
nWidth * stImageInfo.
nHeight * 4 + 2048);
if (NULL == pDataForRGB)
{
break;
}
if (MV_OK != nRet)
{
printf("MV_CC_ConvertPixelType fail! nRet [%x]\n", nRet);
break;
}
FILE* fp = fopen("AfterConvert_RGB.raw", "wb");
if (NULL == fp)
{
printf("fopen failed\n");
break;
}
fclose(fp);
printf("convert succeed\n");
break;
}
case 2:
{
pDataForSaveImage = (
unsigned char*)malloc(stImageInfo.
nWidth * stImageInfo.
nHeight * 4 + 2048);
if (NULL == pDataForSaveImage)
{
break;
}
if(MV_OK != nRet)
{
printf("failed in MV_CC_SaveImage,nRet[%x]\n", nRet);
break;
}
FILE* fp = fopen("image.bmp", "wb");
if (NULL == fp)
{
printf("fopen failed\n");
break;
}
fwrite(pDataForSaveImage, 1, stSaveParam.
nImageLen, fp);
fclose(fp);
printf("save image succeed\n");
break;
}
default:
break;
}
}
if (MV_OK != nRet)
{
printf("MV_CC_StopGrabbing fail! nRet [%x]\n", nRet);
break;
}
if (MV_OK != nRet)
{
printf("MV_CC_DestroyHandle fail! nRet [%x]\n", nRet);
break;
}
} while (0);
if (nRet != MV_OK)
{
if (handle != NULL)
{
handle = NULL;
}
}
if (pData)
{
free(pData);
}
if (pDataForRGB)
{
free(pDataForRGB);
pDataForRGB = NULL;
}
if (pDataForSaveImage)
{
free(pDataForSaveImage);
pDataForSaveImage = NULL;
}
PressEnterToExit();
printf("exit\n");
return 0;
}