pythonopencvximea

Set downsampling for Ximea camera


I am attempting to configure downsampling for the MC023CG-SY-UB Ximea camera. When I invoke the following setters in the python API:

cam.set_imgdataformat('XI_RGB24');
cam.set_gain(20);
cam.disable_aeag();
cam.enable_auto_wb();
cam.set_exposure(7000);
cam.set_downsampling('XI_DWN_2x2');

I get this error:

xiAPI: XiApiToGentlParamModel::SetDownsampling ERROR setting value 2
xiAPI: xiAPI error: Expected XI_OK in:../API/xiFAPI/interfaces/02_mid/xifapi_Handlers_Setters.gen.h SetParam/Line:55
xiAPI: xiSetParam - error: setting parameter downsampling
Traceback (most recent call last):
File "show_ximea_position.py", line 21, in <module>
    cam.set_downsampling('XI_DWN_2x2');

File "/usr/local/lib/python2.7/site-packages/ximea/xiapi.py", line 611, in set_downsampling
self.set_param('downsampling', downsampling)
File "/usr/local/lib/python2.7/site-packages/ximea/xiapi.py", line 389, in set_param
raise Xi_error(stat)
ximea.xiapi.Xi_error: ERROR 12: Not supported

I tried every XI_DWN_NxN sampling method from 2x2->16x16 mentioned in the documentation, and all yield the same error ( Not supported ). If I use XI_DWN_1x1, the configuration is functional, but the image resolution is way too high.

What functions should I invoke to reduce the resolution of the camera? I know that I can do something like:

cam.set_width 
cam.set_height

but that crops the image, and does not alter the resolution.


Solution

  • Turns out that this message is returned back only if the camera you are using does NOT support downsampling. Your only other option is to reduce the number of pixels you fetch back. In other words, the aforementioned camera supports capture at 1936x1216, but you do not have to capture all of them. In the example below, I am fetching 944x1200.

    width = 944;
    height = 1200;
    cam.set_imgdataformat('XI_RGB24');
    cam.set_width(width);
    cam.set_height(height);
    # this value needs to be in increments of 16
    # math to get this number : 1936 - 944 = 992 / 2 = 496
    cam.set_offsetX(496);
    # 496 / 16 = 31.0 yields valid offset for x for center of image