-
Notifications
You must be signed in to change notification settings - Fork 24
Pass in an image as the first argument when running Plant_Detection.py
or Plant_Detection_GUI.py
or use the default test image soil_image.jpg
.
Call Plant_Detection()
with the image
and/or calibration_img
keyword argument as an image filename or an OpenCV/Numpy image object.
Testing Tip: Try using the test images in the PD
directory.
Call Plant_Detection()
without providing the image
and/or calibration_img
keyword arguments and a photo will be taken by an attached USB camera and processed.
Required input parameters:
- Blur (odd integer) example: 5
- Morph (kernel size) example: 15
- Hue range [(0 - 179), (0 - 179)] example: [160, 20] will include 0-20 and 160-179
- Saturation range [(0 - 255), (0 - 255)] example: [50, 255]
- Value range [(0 - 255), (0 - 255)] example: [50, 255]
- Calibration object separation (in coordinate units) example: 500
- Camera offset from coordinate location (in coordinate units) example: [200, 100]
Other input parameters:
- Calibration objects axis (X or Y): Are the objects to detect parallel with the X or Y axes?
- Bot origin orientation in image (top left, top right, bottom left, bottom right): Which direction is the bot's origin?
- Calibration iterations (1 - 5): allows iterative approach to determining camera rotation
Required input parameters:
- Blur (odd integer) example: 5
- Morph (kernel size) example: 15
- Hue range [(0 - 179), (0 - 179)] example: [30, 90] is green
- Saturation range [(0 - 255), (0 - 255)] example: [50, 255]
- Value range [(0 - 255), (0 - 255)] example: [50, 255]
Verbose (verbose=True
):
Processing Parameters:
-------------------------
Blur kernel size: 15
Morph kernel size: 6
Iterations: 4
Hue:
MIN: 30
MAX: 90
Saturation:
MIN: 20
MAX: 255
Value:
MIN: 20
MAX: 255
-------------------------
Processing image: /home/gabriel/plant-detection/soil_image.jpg
16 plants detected in image.
2 known plants inputted.
Plants at the following machine coordinates ( X Y ) with R = radius are to be saved:
( 200 600 ) R = 100
( 900 200 ) R = 120
14 plants marked for removal.
Plants at the following machine coordinates ( X Y ) with R = radius are to be removed:
( 1429 41 ) R = 74
( 608 43 ) R = 82
( 1260 103 ) R = 3
( 1214 153 ) R = 62
( 1374 216 ) R = 14
( 1286 232 ) R = 62
( 1369 285 ) R = 14
( 1039 412 ) R = 74
( 1532 479 ) R = 81
( 766 500 ) R = 80
( 1309 608 ) R = 149
( 59 677 ) R = 61
( 63 914 ) R = 82
( 773 84 ) R = 20
1 plants marked for safe removal.
Plants at the following machine coordinates ( X Y ) with R = radius were too close to the known plant to remove completely:
( 838 86 ) R = 81
2 detected plants are known or have escaped removal.
Plants at the following machine coordinates ( X Y ) with R = radius have been saved:
( 901 189 ) R = 65
( 236 579 ) R = 91
Condensed:
Calibration complete. (rotation:0.0, scale:1.7182)
16 plants detected in image.
known plants input: [{'y': 600, 'x': 200, 'radius': 100}, {'y': 200, 'x': 900, 'radius': 120}]
parameters input: {'morph': 6, 'H': [30, 90], 'blur': 15, 'S': [20, 255], 'iterations': 4, 'V': [20, 255]}
coordinates input: [600, 400]
Print all JSON (print_all_json=True
):
Input Parameters:
{'morph': 6, 'H': [30, 90], 'blur': 15, 'S': [20, 255], 'iterations': 4, 'V': [20, 255]}
Plants (input and output):
{'known': [{'y': 600, 'x': 200, 'radius': 100}, {'y': 200, 'x': 900, 'radius': 120}], 'save': [{'y': 189.01, 'x': 901.37, 'radius': 65.32}, {'y': 579.04, 'x': 236.43, 'radius': 91.23}], 'safe_remove': [{'y': 85.91, 'x': 837.8, 'radius': 80.52}], 'remove': [{'y': 41.24, 'x': 1428.86, 'radius': 73.59}, {'y': 42.96, 'x': 607.56, 'radius': 82.26}, {'y': 103.1, 'x': 1260.48, 'radius': 3.44}, {'y': 152.92, 'x': 1214.09, 'radius': 62.0}, {'y': 216.5, 'x': 1373.88, 'radius': 13.82}, {'y': 231.96, 'x': 1286.25, 'radius': 61.8}, {'y': 285.23, 'x': 1368.72, 'radius': 14.4}, {'y': 412.37, 'x': 1038.83, 'radius': 73.97}, {'y': 479.38, 'x': 1531.95, 'radius': 80.96}, {'y': 500.0, 'x': 765.64, 'radius': 80.02}, {'y': 608.25, 'x': 1308.59, 'radius': 148.73}, {'y': 676.97, 'x': 59.46, 'radius': 60.95}, {'y': 914.09, 'x': 62.89, 'radius': 82.37}, {'y': 84.2, 'x': 772.51, 'radius': 20.06}]}
Calibration data (input and output):
{'calibration_iters': 3, 'H': [160, 20], 'total_rotation_angle': 0.0, 'center_pixel_location': [465, 290], 'S': [100, 255], 'V': [100, 255], 'calibration_circle_separation': 1000, 'morph': 15, 'coord_scale': 1.7182, 'camera_offset_coordinates': [200, 100], 'image_bot_origin_location': [0, 1], 'blur': 5, 'calibration_circles_xaxis': True}
plant-detection_inputs.json
- Input Parameters see above
plant-detection_plants.json
- Plants (input and output) see above
plant-detection_p2c_calibration_parameters.json
- Calibration data (input and output) see above
If run as a farmware (app=True
):
Database (Web App API)
Requests will be made through the FarmBot API to get a list of known plant locations and to upload detected plants to remove.
Settings (FarmBotOS)
Environment variables will be saved with input parameters and calibration data.
Circle Plants (circle_plants=True
)
Draw Contours (draw_contours=True
)
Clump Buster (clump_buster=True
)
Grey Out Background (grey_out=True
)
Grid (included if detected plant coordinates are requested and calibration data has been provided)
Result
Without calibration:
With calibration: (coordinates=True
)
Debug (debug=True
)
Blurred
Masked (using HSV range)
Masked (showing original image)
Morphed (using morph
and iterations
)
Morphed (showing original image)
Contours (plant boundaries)
Contours (with original image)
Array Input Results (Morphed with original image)