Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWB issue #7

Open
ltp7 opened this issue Mar 26, 2020 · 4 comments
Open

AWB issue #7

ltp7 opened this issue Mar 26, 2020 · 4 comments

Comments

@ltp7
Copy link

ltp7 commented Mar 26, 2020

Hi,

I have a problem when trying to execute the do_awb() function. Python 3 gives me the following error:
Traceback (most recent call last):
File "_ctypes/callbacks.c", line 234, in 'calling callback function'
File "/media/luca/70B60ED66D483C58/travail_luca/Pollen_Reader/code/controle/controle_python/camera.py", line 216, in temptint_cb
callback((temp, tint))
TypeError: function name must be string, bytes object or integer

Can you please help ? Thanks in advance,

ltp7

@jirhiker
Copy link
Member

try changing do_awb in camera.py to

    def do_awb(self, callback=None):
        """
        Toupcam_AwbOnePush(HToupCam h, PITOUPCAM_TEMPTINT_CALLBACK fnTTProc, void* pTTCtx);
        :return:
        """

        def temptint_cb(temp, tint):
            if callback:
                callback((temp, tint))

        self._temptint_cb = ctypes.CFUNCTYPE(None, ctypes.c_uint, ctypes.c_void_p)(temptint_cb)

        return self._lib_func('AwbOnePush', self._temptint_cb)

@ltp7
Copy link
Author

ltp7 commented Mar 27, 2020

Thanks for your help. The code now works without error, however the image taken using python code with do_awb() still has different color than the one taken imageusing Touplite (see touplite_awb.jpg and python_awb.jpg attached).

I also tried to manually set the temperature and tint using the values Touplite found for AWB (8458, 1299 in my case) which resulted in the image python_mwb.jpg, which has the same colors as python_awb.jpg, that is, more reddish than touplite_awb.jpg. I suspect the values (8458, 1299), while being both displayed in Touplite as the values used for doing AWB, and being used by do_awb() in camera.py, do not correspond to the actual values used by Touplite... Or maybe they are, but toupcam's python implementation of AWB does not work with the same temperature and tint values as Touplite.

Any thoughts ? Thanks in advance

Python AWB:

python_awb

Touplite AWB:

touplite_awb

Python MWB:

python_mwb

@ltp7
Copy link
Author

ltp7 commented Mar 27, 2020

Update: I've added a time.(3) after calling do_awb() in my code, and now it seems the background color is quite satisfying:

Python AWB:

python_awb

Touplite AWB:

touplite_awb

@jirhiker
Copy link
Member

you can try the following to print the calculated temp and tint then take a picture

cam = ToupCamCamera(cid=...)
    if cam.open():
        time.sleep(1)
        cam.save('no_awb.jpg')

        def awb_hook(te, ti):
            print('temp={}, tint={}'.format(te, ti))
            cam.save('via_hook_awb.jpg')

        cam.do_awb(callback=awb_hook)

        # pic saved by `awb_hook` or here manually
        #time.sleep(1)
        #cam.save('awb.jpg')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants