From 14539259c2ac551cc28075cb23ad7b6d260af749 Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 30 Oct 2019 19:27:01 -0400 Subject: [PATCH 1/2] add control of autoexposure and lighting metering --- src/Camera.jl | 9 ++++---- src/camera/acquisition.jl | 46 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/Camera.jl b/src/Camera.jl index cae18e3..c5896bc 100644 --- a/src/Camera.jl +++ b/src/Camera.jl @@ -8,6 +8,7 @@ export serial, model, vendor, isrunning, start!, stop!, getimage, getimage!, sav trigger!, exposure, exposure!, exposure_limits, autoexposure_limits, autoexposure_limits!, + autoexposure_metering_mode!, autoexposure_lighting_mode!, framerate, framerate!, framerate_limits, gain, gain!, gain_limits, adcbits, adcbits!, @@ -38,7 +39,7 @@ mutable struct Camera names = Dict{String, String}() cam = new(handle, names) finalizer(_release!, cam) - + # Activate chunk mode set!(SpinBooleanNode(cam, "ChunkModeActive"), true) _chunkselect(cam, ["FrameID", "FrameCounter"], "frame indentification") @@ -49,7 +50,7 @@ mutable struct Camera cam.names["AutoExposureTimeLowerLimit"] = "AutoExposureTimeLowerLimit" cam.names["AutoExposureTimeUpperLimit"] = "AutoExposureTimeUpperLimit" cam.names["AcquisitionFrameRateEnabled"] = "AcquisitionFrameRateEnabled" - + try Spinnaker.get(Spinnaker.SpinFloatNode(cam, "AutoExposureTimeLowerLimit")) catch @@ -75,7 +76,7 @@ function _chunkselect(cam::Camera, chunknames::Vector{String}, desc::String) fail = true i = 1 while fail == true - try + try fail = false set!(SpinEnumNode(cam, "ChunkSelector"), chunknames[i]) set!(SpinBooleanNode(cam, "ChunkEnable"), true) @@ -248,7 +249,7 @@ end format, and thus the array will be in the range [0,1]. To return images compatible with Images.jl, one can request a Gray value, e.g., - `getimage!(cam, Gray{N0f8}, normalize=true)`. + `getimage!(cam, Gray{N0f8}, normalize=true)`. Function also returns image ID and timestamp metadata. """ diff --git a/src/camera/acquisition.jl b/src/camera/acquisition.jl index 933b6ff..2a225da 100644 --- a/src/camera/acquisition.jl +++ b/src/camera/acquisition.jl @@ -148,6 +148,52 @@ function autoexposure_limits(cam::Camera) get(SpinFloatNode(cam, cam.names["AutoExposureTimeUpperLimit"]))) end +""" + autoexposure_lighting_mode!(::Camera, mode::String) + + Change autoexposure lighting mode. + Options: + - "AutoDetect": + - "Backlight": Used when a strong light is coming from the back of the object. + - "Frontlight": Used when a strong light is shining in the front of the object + while the background is dark. + - "Normal": Used when the object is not under backlight or frontlight conditions +""" +function autoexposure_lighting_mode!(cam::Camera, mode::String) + if in(mode, ["AutoDetect", "Backlight", "Frontlight", "Normal"]) + set!(SpinEnumNode(cam, "AutoExposureLightingMode"), mode) + else + @error """Lighting mode "$(mode)" not recognized""" + end +end + +""" + autoexposure_metering_mode!(::Camera) + + Change to "Normal" lighting mode and set the autoexposure metering mode. + Options: + - "Average": Measures the light from the entire scene uniformly to determine + the final exposure value. Every portion of the exposed area has + the same contribution. + - "Spot": Measures a small area (about 3%) in the center of the scene while + the rest of the scene is ignored. This mode is used when the + scene has a high contrast and the object of interest is relatively + small. + - "Partial": Measures the light from a larger area (about 11%) in the center + of the scene. This mode is used when very dark or bright regions + appear at the edge of the frame. + - "CenterWeighted" + - "HistgramPeak" +""" +function autoexposure_metering_mode!(cam::Camera, mode::String) + if in(mode, ["Average","Spot","Partial","CenterWeighted","HistgramPeak"]) + autoexposure_lighting_mode!(cam, "Normal") + set!(SpinEnumNode(cam, "AutoExposureMeteringMode"), mode) + else + @error """Metering mode "$(mode)" not recognized""" + end +end + """ framerate(::Camera) -> Float From 9dfb1d377564c03108f461090656cc8cab89914a Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 30 Oct 2019 19:33:35 -0400 Subject: [PATCH 2/2] tweak docstrings --- src/camera/acquisition.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/camera/acquisition.jl b/src/camera/acquisition.jl index 2a225da..48922fe 100644 --- a/src/camera/acquisition.jl +++ b/src/camera/acquisition.jl @@ -153,7 +153,7 @@ end Change autoexposure lighting mode. Options: - - "AutoDetect": + - "AutoDetect": Automatically detect - "Backlight": Used when a strong light is coming from the back of the object. - "Frontlight": Used when a strong light is shining in the front of the object while the background is dark. @@ -170,7 +170,7 @@ end """ autoexposure_metering_mode!(::Camera) - Change to "Normal" lighting mode and set the autoexposure metering mode. + Change autoexposure lighting mode to "Normal" and set the autoexposure metering mode. Options: - "Average": Measures the light from the entire scene uniformly to determine the final exposure value. Every portion of the exposed area has @@ -182,8 +182,8 @@ end - "Partial": Measures the light from a larger area (about 11%) in the center of the scene. This mode is used when very dark or bright regions appear at the edge of the frame. - - "CenterWeighted" - - "HistgramPeak" + - "CenterWeighted": (No SDK docs) + - "HistgramPeak": (No SDK docs) """ function autoexposure_metering_mode!(cam::Camera, mode::String) if in(mode, ["Average","Spot","Partial","CenterWeighted","HistgramPeak"])