Skip to content

Instantly share code, notes, and snippets.

@Mallekin
Created May 7, 2018 16:07
Show Gist options
  • Save Mallekin/14b83dce512e1f67e2a0fdb0499f6183 to your computer and use it in GitHub Desktop.
Save Mallekin/14b83dce512e1f67e2a0fdb0499f6183 to your computer and use it in GitHub Desktop.
Minimal python example to capture frames with an IDS uEye camera
from pyueye import ueye
import numpy as np
import cv2
def main():
# init camera
hcam = ueye.HIDS(0)
ret = ueye.is_InitCamera(hcam, None)
print(f"initCamera returns {ret}")
# set color mode
ret = ueye.is_SetColorMode(hcam, ueye.IS_CM_BGR8_PACKED)
print(f"SetColorMode IS_CM_BGR8_PACKED returns {ret}")
# set region of interest
width = 1280
height = 1080
rect_aoi = ueye.IS_RECT()
rect_aoi.s32X = ueye.int(0)
rect_aoi.s32Y = ueye.int(0)
rect_aoi.s32Width = ueye.int(width)
rect_aoi.s32Height = ueye.int(height)
ueye.is_AOI(hcam, ueye.IS_AOI_IMAGE_SET_AOI, rect_aoi, ueye.sizeof(rect_aoi))
print(f"AOI IS_AOI_IMAGE_SET_AOI returns {ret}")
# allocate memory
mem_ptr = ueye.c_mem_p()
mem_id = ueye.int()
bitspixel = 24 # for colormode = IS_CM_BGR8_PACKED
ret = ueye.is_AllocImageMem(hcam, width, height, bitspixel,
mem_ptr, mem_id)
print(f"AllocImageMem returns {ret}")
# set active memory region
ret = ueye.is_SetImageMem(hcam, mem_ptr, mem_id)
print(f"SetImageMem returns {ret}")
# continuous capture to memory
ret = ueye.is_CaptureVideo(hcam, ueye.IS_DONT_WAIT)
print(f"CaptureVideo returns {ret}")
# get data from camera and display
lineinc = width * int((bitspixel + 7) / 8)
while True:
img = ueye.get_data(mem_ptr, width, height, bitspixel, lineinc, copy=True)
img = np.reshape(img, (height, width, 3))
cv2.imshow('uEye Python Example (q to exit)', img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
# cleanup
ret = ueye.is_StopLiveVideo(hcam, ueye.IS_FORCE_VIDEO_STOP)
print(f"StopLiveVideo returns {ret}")
ret = ueye.is_ExitCamera(hcam)
print(f"ExitCamera returns {ret}")
if __name__ == '__main__':
main()
@qshtykoo
Copy link

Hello! I wonder how I can set up exposure time, gain such parameters?

@mehmetkacmaz
Copy link

When I run this code, camera stayed zoomed. Which code part is reasoning this. Can you help me about this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment