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

Contrast #16

Closed
chiuwe opened this issue Feb 10, 2020 · 21 comments
Closed

Contrast #16

chiuwe opened this issue Feb 10, 2020 · 21 comments
Labels
enhancement New feature or request

Comments

@chiuwe
Copy link

chiuwe commented Feb 10, 2020

How do i adjust contrast?
Do i need to add it myself?

@zingmars
Copy link
Owner

As far as I can tell Pylon 5.0.12 does not let you set contrast values, and as such this plugin does not have this functionality.

@zingmars zingmars added the question Further information is requested label Feb 11, 2020
@chiuwe
Copy link
Author

chiuwe commented Feb 11, 2020

Just curious, where do you check if pylon supports certain functions or not?
From this page it looks like basler does support certain functions. I dont know how this relates to pylon though.
https://docs.baslerweb.com/brightness-and-contrast.html

@zingmars
Copy link
Owner

The pylon redist comes with header files and docs that describe all available functions. If it's not there, it's usually a sign that it's not available.

The docs you linked seem to be from Pylon 6.0, but as far as I can tell it's only available for Windows right now.

@chiuwe
Copy link
Author

chiuwe commented Feb 11, 2020

I do agree with you that contrast doesnt exist for Pylon 5.0.12 in C. But the docs do show contrast settings in C++. Is there a reason why we can't use C++?

@zingmars
Copy link
Owner

gstreamer plugins are written in C using gobject etc libs. It might be possible, but I suspect gobject won't play well with C++, if at all.

I don't know if they're suitable for your use case, but AppSrc plugins can be written in C++, and there's one for pylon available here https://github.com/MattsProjects/pylon_gstreamer

@zingmars
Copy link
Owner

zingmars commented Feb 11, 2020

Ah, looking at the docs again, I guess I missed the struct entries the first time because the doc search they have is broken (had to grep for them).

Yeah, you should be able to add it by just adding the instructions to set BslContrast, i.e. PylonDeviceSetFloatFeature(pylonsrc->deviceHandle, "BslContrast", <value>);.

for BslContrastMode, you'll need PylonDeviceFeatureFromString(pylonsrc->deviceHandle, "BslContrastMode", <value>);, where value can be either Linear or SCurve.

You'll need to check for the features first using PylonDeviceFeatureIsAvailable. From what I gather these will only work with dart and pulse cameras (not ace).

@zingmars zingmars added enhancement New feature or request and removed question Further information is requested labels Feb 11, 2020
@chiuwe
Copy link
Author

chiuwe commented Feb 11, 2020

Just to make sure i'm on the same page, are you looking at docs in .../pylon5/share/doc/BPD/?

@zingmars
Copy link
Owner

I use the C++ docs to look at the classes, i.e. C++/class_basler___usb_camera_params_1_1_c_usb_camera_params___params.html#a330bd845cac1b1631066736d857220f3. When developing this I basically took everything pylon gave me for my camera (it was an ace), and just implemented it into the plugin (which is why contrast controls are missing). The BPD docs had a bunch of stuff I didn't need, so I didn't use them.

@chiuwe
Copy link
Author

chiuwe commented Feb 12, 2020

how do i go about troubleshooting the camera? I'm using a dart and i implemented the contrast. The camera doesnt seem to be throwing any error, but contrast also isnt changing as expected.

@zingmars
Copy link
Owner

Does it change at all? Does it change properly using the Pylon viewer app? How different are the results you get from the viewer app and gstreamer video output?

@chiuwe
Copy link
Author

chiuwe commented Feb 12, 2020

it doesnt change at all, when pull the parameter GST_DEBUG_OBJECT(pylonsrc, "The resulting contrast is %.0lf.", contrastRate); after i set it, it still returns 0.

if(PylonDeviceFeatureIsAvailable(pylonsrc->deviceHandle, "BslContrast")) {
    GST_DEBUG_OBJECT(pylonsrc, "Setting contrast to %.2lf", pylonsrc->contrast);
    res = PylonDeviceFeatureFromString(pylonsrc->deviceHandle, "BslContrastMode", "Linear");
    PYLONC_CHECK_ERROR(pylonsrc, res);
    res = PylonDeviceSetFloatFeature(pylonsrc->deviceHandle, "BslContrast", pylonsrc->contrast);
    PYLONC_CHECK_ERROR(pylonsrc, res);

    double contrastRate = 0.0;

    res = PylonDeviceGetFloatFeature(pylonsrc->deviceHandle, "BslContrast", &contrastRate);
    PYLONC_CHECK_ERROR(pylonsrc, res);

    GST_DEBUG_OBJECT(pylonsrc, "The resulting contrast is %.0lf.", contrastRate);

  } else {
    GST_WARNING_OBJECT(pylonsrc, "This camera doesn't support contrast.");
  }

when i adjust contrast in the viewer it does change the output 0->.22 results in a brighter image.
In gstreamer video output it looks the same as 0.

@zingmars
Copy link
Owner

What does PylonDeviceFeatureIsWritable(pylonsrc->deviceHandle, "BslContrast") return?

@chiuwe
Copy link
Author

chiuwe commented Feb 12, 2020

it returns true.

0:00:01.177648058 35322 0x5617454b4630 DEBUG               pylonsrc gstpylonsrc.c:1067:gst_pylonsrc_start:<pylonsrc0> Is contrast writeable: 1.
0:00:01.177689018 35322 0x5617454b4630 DEBUG               pylonsrc gstpylonsrc.c:1068:gst_pylonsrc_start:<pylonsrc0> Setting contrast to 0.22
0:00:01.222329427 35322 0x5617454b4630 DEBUG               pylonsrc gstpylonsrc.c:1079:gst_pylonsrc_start:<pylonsrc0> The resulting contrast is 0.

@zingmars
Copy link
Owner

Hm, this is really weird. I've never seen a situation where it fails to set a value without an error message like this. And without a camera there's very little I can do myself to test it. Sorry I couldn't be of more help :(

@chiuwe
Copy link
Author

chiuwe commented Feb 12, 2020

so i'm also trying adjust saturation. The doc says that saturation is only available for YCbCr422-8 or RGB8 format. I'm using YCbCr422-8 but when i check to see if saturation is available it returns false.
I can see in the pylon viewer changing the image format will gray out/not gray out saturation.
I'm wondering if the image format isn't set yet when i trying to change saturation?
i adjust saturation after your plugin prints out pylonsrc gstpylonsrc.c:1255:gst_pylonsrc_start:<pylonsrc0> Using YCbCr422_8 image format.

@zingmars
Copy link
Owner

Does it happen if you set the correct format in pylon viewer, then stop it from streaming without disconnecting the device (close the viewer) and run the plugin? All active settings are saved in camera's RAM (at least ace's were), so if you set something up in the viewer the settings should carry on to the output of the plugin as well (as long as the plugin doesn't overwrite them, which it does for some settings).

@chiuwe
Copy link
Author

chiuwe commented Feb 12, 2020

I can't run gstreamer plugin while device is still connected to pylon viewer. It looks like the default pixel format is YCbCr422-8, so i dont understand why i can't set saturation. It looks like like none of the settings is saved in RAM for this camera. I'm trying to get in touch with basler, maybe they can help me debug their own hardware

@zingmars
Copy link
Owner

zingmars commented Feb 12, 2020 via email

@MattsProjects
Copy link

Hi there,
For the contrast issue, I think that maybe you are not completely implementing this into the code?
I attached the .h and .c that I just edited over here and a screenshot. It seems to work fine for me...
For the saturation issue, maybe check the order of operations here. The pixel format must be set first before the saturation becomes available. So when I set "imageformat=YCbCr422_8 colorredsaturation=1.2", that worked.
Screenshot from 2020-02-14 11-44-24
Screenshot from 2020-02-14 11-44-48
Screenshot from 2020-02-14 11-45-03
Screenshot from 2020-02-14 11-45-17
gstpylonsrc_edit.zip

@chiuwe
Copy link
Author

chiuwe commented Feb 14, 2020

Hi Matt,

Thank you for helping me out.
I looked at your code for contrast and it looks identical to mine.
I found a bug with mine though.
GST_DEBUG_OBJECT(pylonsrc, "The resulting contrast is %.0lf.", contrastRate);
which is why it would return 0 when i try to set it to .22.

But I still can't get saturation to work.
my dart camera doesnt support saturation via color adjustment (COLORREDSATURATION, COLORYELLOWSATURATION, etc)
The doc says I should be using 'BslSaturation'.
but it returns false when i queue it with PylonDeviceFeatureIsAvailable().
I believe that the pixelFormat is already set before i try to set saturation.
Ive included my code for you to review.
gstpylonsrc-mod.zip

@MattsProjects
Copy link

Hi Steven,
Try "BslSaturationValue" instead. I think our documentation here has a typo (perhaps the section is a bit outdated). :-(.
If possible, try to use the pylon viewer as the first go to for feature names. It is pulling the xml file directly from the camera.
Sorry for this!
-Matt

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

No branches or pull requests

3 participants