Skip to content

Instantly share code, notes, and snippets.

@jeremy-rutman
Forked from TobiSchr/test_frame_capture.c
Last active May 15, 2019 18:52
Show Gist options
  • Save jeremy-rutman/e360c16a2e28e06d18bc9228aba8514c to your computer and use it in GitHub Desktop.
Save jeremy-rutman/e360c16a2e28e06d18bc9228aba8514c to your computer and use it in GitHub Desktop.
Simple example to capture a frame with an uEye Camera under Linux; compile with: gcc -Wall test_frame_capture.c -lueye_api -o frametest
#include<string.h>
#include<stdio.h>
#include<stddef.h>
#include<ueye.h>
/********
This allows for changing cam and exposure.
Also an attempt is made to use monochrome cam at 10bits - actual image is 24bpp.
If you take the first (red) channel from this it appears ok, havent attempted to locate final 2 bits.
*********/
HIDS hCam = 1;
int main(int argc, char *argv[]) {
int count=0;
int r = 0 ;
double ex = 5.0;
int cam = 1;
if (argc > 1)
{
printf("argc %d\nx",argc);
for (count = 1; count < argc; count++)
{
printf("argv[%d] = %s\n", count, argv[count]);
if (strcmp(argv[count],"exposure")==0)
{
printf("got exposure \n");
if (argc<count+2)
{
printf("too few args (nothing after exposure)");
}
else
{
printf("enough args\n");
r = sscanf(argv[count+1],"%lf", &ex);
printf("exposure %lf retval %d \n",ex,r);
}
}
if (strcmp(argv[count],"camera")==0)
{
printf("got camera \n");
if (argc<count+2)
{
printf("too few args (nothing after cam)");
}
else
{
printf("enough args\n");
r = sscanf(argv[count+1],"%d", &cam);
printf("cam %d retval %d \n",cam,r);
}
}
}
}
hCam = cam ;
printf("Success-Code: %d\n",IS_SUCCESS);
//Kamera öffnen
INT nRet = is_InitCamera (&hCam, NULL);
printf("Status Init %d\n",nRet);
//Pixel-Clock setzen
UINT nPixelClockDefault = 9;
nRet = is_PixelClock(hCam, IS_PIXELCLOCK_CMD_SET,
(void*)&nPixelClockDefault,
sizeof(nPixelClockDefault));
printf("Status is_PixelClock %d\n",nRet);
//Farbmodus der Kamera setzen
//INT colorMode = IS_CM_CBYCRY_PACKED;
// INT colorMode = IS_CM_BGR8_PACKED;
// INT colorMode = COLOR_MONO_8;
// INT colorMode = IS_CM_MONO8;
// INT colorMode = IS_CM_MONO10;
// INT colorMode = IS_CM_MONO12;
INT colorMode = IS_CM_MONO16;
// #define IS_COLORMODE_MONOCHROME 1
//#define IS_COLORMODE_BAYER 2
//#define IS_COLORMODE_CBYCRY 4
//#define IS_COLORMODE_JPEG
nRet = is_SetColorMode(hCam,colorMode);
printf("Status SetColorMode %d\n",nRet);
// UINT cm=0;
// nRet = is_GetColorDepth(hCam,&cm);
// printf("Status GetColorMode %d val %d\n",nRet,cm);
UINT formatID = 4;
//Bildgröße einstellen -> 2592x1944
nRet = is_ImageFormat(hCam, IMGFRMT_CMD_SET_FORMAT, &formatID, 4);
printf("Status ImageFormat %d\n",nRet);
//Speicher für Bild alloziieren
char* pMem = NULL;
int memID = 0;
nRet = is_AllocImageMem(hCam, 2592, 1944, 16, &pMem, &memID);
printf("Status AllocImage %d\n",nRet);
//diesen Speicher aktiv setzen
nRet = is_SetImageMem(hCam, pMem, memID);
printf("Status SetImageMem %d\n",nRet);
//Bilder im Kameraspeicher belassen
INT displayMode = IS_SET_DM_DIB;
nRet = is_SetDisplayMode (hCam, displayMode);
printf("Status displayMode %d\n",nRet);
//Bild aufnehmen
nRet = is_FreezeVideo(hCam, IS_WAIT);
printf("Status is_FreezeVideo %d\n",nRet);
double exposure;
nRet = is_Exposure(hCam, IS_EXPOSURE_CMD_GET_EXPOSURE, &exposure, sizeof(exposure));
// nRet = is_Exposure(hcam, IS_EXPOSURE_CMD_SET_EXPOSURE, (void*) &exposure, sizeof(exposure));
printf("exposure stat %d exposure %f \n",nRet,exposure);
exposure=ex;
nRet = is_Exposure(hCam, IS_EXPOSURE_CMD_SET_EXPOSURE, &exposure, sizeof(exposure));
printf("exposure stat %d set exposure %f \n",nRet,exposure);
nRet = is_Exposure(hCam, IS_EXPOSURE_CMD_GET_EXPOSURE, &exposure, sizeof(exposure));
// nRet = is_Exposure(hcam, IS_EXPOSURE_CMD_SET_EXPOSURE, (void*) &exposure, sizeof(exposure));
printf("exposure stat %d get exposure %f \n",nRet,exposure);
//Bild aus dem Speicher auslesen und als Datei speichern
IMAGE_FILE_PARAMS ImageFileParams;
/* ImageFileParams.pwchFileName = L"/home/nvidia/images/snap_BGR8.png";
ImageFileParams.pnImageID = NULL;
ImageFileParams.ppcImageMem = NULL;
ImageFileParams.nQuality = 0;
ImageFileParams.nFileType = IS_IMG_PNG;
nRet = is_ImageFile(hCam, IS_IMAGE_FILE_CMD_SAVE, (void*) &ImageFileParams, sizeof(ImageFileParams));
printf("Status is_ImageFile %d\n",nRet);
ImageFileParams.pwchFileName = L"/home/nvidia/images/snap_BGR8.bmp";
ImageFileParams.pnImageID = NULL;
ImageFileParams.ppcImageMem = NULL;
ImageFileParams.nQuality = 0;
ImageFileParams.nFileType = IS_IMG_BMP;
nRet = is_ImageFile(hCam, IS_IMAGE_FILE_CMD_SAVE, (void*) &ImageFileParams, sizeof(ImageFileParams));
printf("Status is_ImageFile %d\n",nRet);
*/
ImageFileParams.pwchFileName = L"./snap_mono16.jpg";
ImageFileParams.pnImageID = NULL;
ImageFileParams.ppcImageMem = NULL;
ImageFileParams.nQuality = 0;
ImageFileParams.nFileType = IS_IMG_JPG;
nRet = is_ImageFile(hCam, IS_IMAGE_FILE_CMD_SAVE, (void*) &ImageFileParams, sizeof(ImageFileParams));
printf("Status is_ImageFile %d\n",nRet);
//Kamera wieder freigeben
is_ExitCamera(hCam);
}
/*
static int ids_core_Camera_setexposure(ids_core_Camera *self, PyObject *value, void *closure) {
int ret;
double exposure;
PyObject *exception;
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "Cannot delete attribute 'exposure'");
return -1;
}
exposure = PyFloat_AsDouble(value);
exception = PyErr_Occurred();
if (exception) {
PyErr_SetString(exception, "Exposure must be a number");
return -1;
}
ret = is_Exposure(self->handle, IS_EXPOSURE_CMD_SET_EXPOSURE, (void*) &exposure, sizeof(exposure));
switch (ret) {
case IS_SUCCESS:
return 0;
break;
case IS_INVALID_PARAMETER:
PyErr_SetString(PyExc_ValueError, "Exposure out of range");
break;
default:
raise_general_error(self, ret);
}
return -1;
}
static PyObject *ids_core_Camera_getexposure(ids_core_Camera *self, void *closure) {
double exposure;
int ret;
ret = is_Exposure(self->handle, IS_EXPOSURE_CMD_GET_EXPOSURE, &exposure, sizeof(exposure));
switch (ret) {
case IS_SUCCESS:
return PyFloat_FromDouble(exposure);
break;
default:
raise_general_error(self, ret);
}
return NULL;
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment