imgProcessor.camera package¶
A collection to execute a camera calibration and to correct am image, removing lens, perspective etc. distortions
Submodules¶
imgProcessor.camera.CameraCalibration module¶
-
class
imgProcessor.camera.CameraCalibration.
CameraCalibration
[source]¶ Bases:
object
Collect a arrays and parameters needed for camera calibration (.add###) Load and save to hard drive (.loadFromFile, .saveToFile) and correct images (.correct)
-
addDarkCurrent
(slope, intercept, date=None, info='', error=None)[source]¶ Parameters: - slope (float) –
- intercept (np.array) –
- error (float) –
- slope – dPx/dExposureTime[sec]
- error – absolute
- date (str) – “DD Mon YY” e.g. “30 Nov 16”
-
addFlatField
(arr, date=None, info='', error=None, light_spectrum='visible')[source]¶ light_spectrum = light, IR ...
-
addLens
(lens, date, info='', light_spectrum='visible')[source]¶ lens -> instance of LensDistortion or saved file
-
addNoise
(nlf_coeff, date=None, info='', error=None)[source]¶ Parameters: - nlf_coeff (list) –
- error (float) – absolute
- info (str) – additional information
- date (str) – “DD Mon YY” e.g. “30 Nov 16”
-
clearOldCalibrations
(date=None)[source]¶ if not only a specific date than remove all except of the youngest calibration
-
correct
(image1, image2=None, bgImages=None, exposure_time=None, light_spectrum=None, threshold=0.2, keep_size=True, date=None, deblur=True)[source]¶ exposure_time [s]
- date -> string e.g. ‘30. Nov 15’ to get a calibration on from date
- -> {‘dark current’:‘30. Nov 15’,
- ‘flat field’:‘15. Nov 15’, ‘lens’:‘14. Nov 15’, ‘noise’:‘01. Nov 15’}
-
dates
(typ, light=None)[source]¶ Parameters: - typ – type of calibration to look for. See .coeffs.keys() for all types available
- light (Optional[str]) – restrict to calibrations, done given light source
Returns: All calibration dates available for given typ
Return type: list
-
ftype
= '.cal'¶
-
getCoeff
(name, light, date)[source]¶ try to get calibration for right light source, but use another if they is none existent
-
infos
(typ, light=None, date=None)[source]¶ Parameters: - typ – type of calibration to look for. See .coeffs.keys() for all types available
- date (Optional[str]) – date of calibration
Returns: all infos available for given typ
Return type: list
-
imgProcessor.camera.DarkCurrentMap module¶
-
class
imgProcessor.camera.DarkCurrentMap.
DarkCurrentMap
(twoImages, noise_level_function=None, calcVariance=False, **kwargs)[source]¶ Bases:
imgProcessor.utils.baseClasses.Iteratives
Averages given background images removing single time effects
-
imgProcessor.camera.DarkCurrentMap.
averageSameExpTimes
(imgs_path)[source]¶ average background images with same exposure time
-
imgProcessor.camera.DarkCurrentMap.
getDarkCurrentAverages
(exposuretimes, imgs)[source]¶ return exposure times, image averages for each exposure time
-
imgProcessor.camera.DarkCurrentMap.
getDarkCurrentFunction
(exposuretimes, imgs, **kwargs)[source]¶ get dark current function from given images and exposure times
imgProcessor.camera.FlatFieldFromImgFit module¶
-
class
imgProcessor.camera.FlatFieldFromImgFit.
FlatFieldFromImgFit
(images=None, nstd=3, ksize=None, scale_factor=None)[source]¶ Bases:
object
imgProcessor.camera.LensDistortion module¶
-
class
imgProcessor.camera.LensDistortion.
LensDistortion
(coeffs={})[source]¶ Bases:
object
class for detecting and correcting the lens distortion within images
-
addImgStream
(img)[source]¶ add images using a continous stream - stop when max number of images is reached
-
addPoints
(points)[source]¶ add corner points directly instead of extracting them from image points = ( (0,1), (...),... ) [x,y]
-
calibrate
(board_size, method='Chessboard', images=[], max_images=100, sensorSize_mm=None, detect_sensible=False)[source]¶ sensorSize_mm - (width, height) [mm] Physical size of the sensor
-
coeffs
¶
-
drawChessboard
(img=None)[source]¶ draw a grid fitting to the last added image on this one or an extra image img == None
==False -> draw chessbord on empty image ==img
-
ftype
= 'npz'¶
-
getCameraParams
()[source]¶ value positions based on http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#cv.InitUndistortRectifyMap
-
setImgShape
(shape)[source]¶ image shape must be known for calculating camera matrix if method==Manual and addPoints is used instead of addImg this method must be called before .coeffs are obtained
-
imgProcessor.camera.NoiseLevelFunction module¶
-
imgProcessor.camera.NoiseLevelFunction.
boundedFunction
(x, minY, ax, ay)[source]¶ limit [function] to a minimum y value
-
imgProcessor.camera.NoiseLevelFunction.
calcNLF
(img, img2=None, signal=None, mn_mx_nbins=None, x=None, averageFn='AAD', signalFromMultipleImages=False)[source]¶ Calculate the noise level function (NLF) as f(intensity) using one or two image. The approach for this work is published in JPV##########
- img2 - 2nd image taken under same conditions
- used to estimate noise via image difference
- signalFromMultipleImages - whether the signal is an average of multiple
- images and not just got from one median filtered image
-
imgProcessor.camera.NoiseLevelFunction.
estimateFromImages
(imgs1, imgs2=None, mn_mx=None, nbins=100)[source]¶ estimate the noise level function as stDev over image intensity from a set of 2 image groups images at the same position have to show the identical setup, so imgs1[i] - imgs2[i] = noise
imgProcessor.camera.PerspectiveCorrection module¶
-
class
imgProcessor.camera.PerspectiveCorrection.
PerspectiveCorrection
(img_shape, obj_height_mm=None, obj_width_mm=None, cameraMatrix=None, distCoeffs=0, do_correctIntensity=False, new_size=None, in_plane=False, cv2_opts={})[source]¶ Bases:
object
-
camera_position
¶ returns camera position in world coordinates using self.rvec and self.tvec from http://stackoverflow.com/questions/14515200/python-opencv-solvepnp-yields-wrong-translation-vector
-
correct
(img)[source]¶ - ...from perspective distortion:
- –> perspective transformation –> apply tilt factor (view factor) correction
-
distort
(img, rotX=0, rotY=0, quad=None)[source]¶ Apply perspective distortion ion self.img angles are in DEG and need to be positive to fit into image
-
draw3dCoordAxis
(img=None, thickness=8)[source]¶ draw the 3d coordinate axes into given image if image == False:
create an empty image
-
homography
¶
-
obj_points
¶
-
setReference
(ref)[source]¶ ref ... either quad, grid, homography or reference image
- quad –> list of four image points(x,y) marking the edges of the quad
- to correct
homography –> h. matrix to correct perspective distortion referenceImage –> image of same object without perspective distortion
-
standardUncertainties
(focal_Length_mm, f_number, focusAtYX=None, sigma_best_focus=0, quad_pos_err=0, shape=None, uncertainties=((), (), ()))[source]¶ - focusAtXY - image position with is in focus
- if not set it is assumed that the image middle is in focus
- sigma_best_focus - standard deviation of the PSF
- within the best focus (default blur)
- uncertainties - contibutors for standard uncertainty
- these need to be perspective transformed to fit the new image shape
-