Package: cv-recon
AboutA computer vision toolkit focused on color detection and feature matching using OpenCV. It allows you to easily start the picamera in case you're using a Raspberry PI.Some of the stuff you can currently doColor detectionDetect a range of colors in an image using HSV boundaries.Find bounding boxes.Feature matchingDraw matches between a source and target image.Find bounding boxes.PicameraEasily start the picamera.ToolsDraw boxes.Draw boxes' offset from the center of the frame.Stack frames in a grid.DependenciesDependencyInstallationpython3Refer to the officialwebsiteopencvRefer to the officialinstallation guide(tested with version 4.5.2)numpypip install numpypicameraInstalled by default in Raspberry PI OS (required only if working with a picamera)Installationpipinstallcv-reconUsageSee examples in theexamples folderor test it directly form source. Change directorycd cv_recon/recon/once in this folder you can run:CommandDescriptionPreviewpython colorspace.pyGenerates HSV settings to detect a specific colorpython colorspace.py <path to .log file>Loads HSV settings to detect a specific colorpython features.py <path to an image>Performs feature detection against a given imageDocumentationClass: Colorspace(hsv_settings=None)This class allows you to detect a range of colors using HSV boundaries. You can generate the settings or set them directly. See exampleshere.ArgsDescriptionDefaulthsv_settingsPath to .log file containing the HSV settings or list containing lower and upper HSV boundariesNoneImport examplefromcv_reconimportColorspace# load generated settingscolorspace_1=Colorspace('settings.log')# or set hsv lower and upper boundariescolorspace_2=Colorspace([[0,0,0],[179,255,255]])PropertiesPropertyDescriptionTypeDefaultlowerLower HSV boundarylistNoneupperUpper HSV boundarylistNoneim_maskMask obtained from the HSV boundariesnp.arrayNoneim_cutPortions of the frame containing the color boundariesnp.arrayNoneim_edgesCanny edge detection applied toim_masknp.arrayNoneim_contoursContours of the detected objects drawn on the current framenp.arrayNoneMethodsloadSettings(settings)Loads HSV settings from a generated .log file.ArgsDescriptionDefaultsettingsPath to .log file with generated HSV settingsNonereturns:NonedumpSettings(output='last.log')Generates a .log file with the current HSV settings.ArgsDescriptionDefaultoutputPath in which the file is gonna be written'last.log'returns:NonecreateSliders()Creates a window with sliders in order to adjust the HSV settings.returns:NoneupdateHSV()Updates the current HSV settings with the current slider values.returns:NonegetMaskBoxes(im_base, im_hsv, min_area=20, scale=0.1)Generates a list containing the bounding boxes (x, y, w, h) of the objects.ArgsDescriptionDefaultim_baseBase image in bgr formatNoneim_hsvBase image in hsv formatNonemin_areaMinimum area to generate the coordinates20scaleScale of the bounding box0.1returns:bounding_boxesgetMaskBoxesArea(im_base, im_hsv, min_area=20, scale=0.1)Generates two lists containing the bounding boxes (x, y, w, h) and the estimated area of each object.ArgsDescriptionDefaultim_baseBase image in bgr formatNoneim_hsvBase image in hsv formatNonemin_areaMinimum area to generate the coordinates20scaleScale of the bounding box0.1returns:bounding_boxes, areasClass: Features(im_source=None, features=500)This class allows you to easily perform feature matching detection. See exampleshere.ArgsDescriptionDefaultim_sourceSource imageNonefeaturesAmount of features inim_source500Import examplefromcv_reconimportFeaturesimportcv2ascv# load source image (the image you want to detect)im_source=cv.imread('image.jpg')# create Features object (detects 1000 features from the source image)my_feature=Features(im_source,1000)PropertiesPropertyDescriptionTypeDefaultim_sourceSource image (the image you want to detect)np.arrayim_sourceim_source_kpSource image keypointsnp.arrayim_sourcekeypointsim_targetTarget imagenp.arrayNoneim_target_kpTarget image keypointsnp.arrayNoneim_polyImage containing a polygon around the best matchesnp.arrayNoneMethodsloadTarget(im)Loads the target image to perform the feature matching detection.ArgsDescriptionDefaultimTarget image in which the feature matching is gonna be performNonereturns:NonegetMatches(distance=0.75)Generates a list with the good matches found in the target image.ArgsDescriptionDefaultdistanceThreshold which decides if it is a good match0.75returns:good_matchesmatchPoints(matches)Returns an image containing the matches betweenim_targetandim_source.ArgsDescriptionDefaultmatchesList containing the good matchesNonereturns:imagegetBoxes(matches, min_matches=20)Generates a list containing the bounding box (x, y, w, h) of the object.ArgsDescriptionDefaultmatchesGood matchesNonemin_matchesMinimum amount of matches to generate the bounding box20returns:bounding_boxClass: PiCam(resolution=(320, 240), framerate=32, **kargs)This class allows you to easily interact with the picamera. See exampleshere.ArgsDescriptionDefaultresolutionCamera resolution(320, 240)framerateFramerate32**kargsAssign default picamera settings. See a list of the settingshereNoneImport examplefromcv_recon.picamimportPiCam# cam settingsres=(320,240)fps=24# initialize the cameracamera=PiCam(res,fps,brightness=55,contrast=10)PropertiesPropertyDescriptionTypecurrent_frameCurrent framenp.arrayMethodsvideoCapture()Creates a thread which updates the propertycurrent_frame.returns:Nonerelease()Stops updating the propertycurrent_frame.returns:Noneeffects()Prints the list of image effects.returns:NoneexposureModes()Prints the list of exposure modes.returns:NoneawbModes()Prints the list of automatic withe balance modes.returns:NoneModule: cv_toolsThis module allows you generate a grid of images, draw bounding boxes and its offset from the center of the frame.Import examplefromcv_reconimportcv_toolsFunctionsgrid(base, dimensions, images, scale=0.5)Generates anumpy.arraycontaining a grid of images with the given dimensions and scale.ArgsDescriptionDefaultbaseImage with the base dimensions for the rest of the imagesNonedimensionsTupla containing the dimensions of the gridNoneimagesList of images not larger thandimensions[0] * dimensions[1], each image must have the same dimensions asbaseNonescaleScale of the output image0.5Returns:imagegetBoxesOffset(im, boxes)Generates a list containing the offset of each box from the center of the frame.ArgsDescriptionDefaultimImage with the size of the frameNoneboxesList of bounding boxesNoneReturns:[x_offset, y_offset]drawBoxes(im, boxes)Draw the bounding boxes over an image.ArgsDescriptionDefaultimImage in which the bounding boxes are going to be drawnNoneboxesList of bounding boxesNoneReturns:imagedrawBoxesPos(im, boxes)Draw the offset from the center of the frame of each bounding box.ArgsDescriptionDefaultimImage in which the offsets are going to be drawnNoneboxesList of bounding boxesNoneReturns:image