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

Document that block_size must be an odd integer #1426

Open
HaleySchuhl opened this issue Jan 16, 2024 · 0 comments
Open

Document that block_size must be an odd integer #1426

HaleySchuhl opened this issue Jan 16, 2024 · 0 comments
Labels
new feature New feature ideas and solutions
Projects

Comments

@HaleySchuhl
Copy link
Contributor

Is your feature request related to a problem? Please describe.
The updated pcv.transform.detect_color_card function has kwargs that include block_size. An even number for block_size will throw a long and strange cv2 error, see below, so best there's mention in the documentation page transform_detect_color_card.md that block_size must be an odd integer.

Describe the solution you'd like
mention in the documentation page transform_detect_color_card.md that block_size must be an odd integer

Describe alternatives you've considered
add logic to the pcv.transform.detect_color_card function that checks this and throws a pcv error message rather than getting to the cv2 part.

Additional context

error                                     Traceback (most recent call last)
Cell In[34], line 2
      1 # First, detect the color card.
----> 2 card_mask = pcv.transform.detect_color_card(rgb_img=crop_img, adaptive_method=0, radius=15, block_size=10)
      4 # Print average chip size, value is stored in outputs.observations
      5 #print(pcv.outputs.observations['B73']['median_color_chip_size']['value'])
File ~/.local/lib/python3.9/site-packages/plantcv/plantcv/transform/detect_color_card.py:69, in detect_color_card(rgb_img, label, **kwargs)
     67 imgray = cv2.cvtColor(rgb_img, cv2.COLOR_BGR2GRAY)
     68 gaussian = cv2.GaussianBlur(imgray, (11, 11), 0)
---> 69 thresh = cv2.adaptiveThreshold(gaussian, 255, adaptive_method,
     70                                cv2.THRESH_BINARY_INV, block_size, 2)
     71 contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
     73 # Filter contours, keep only square-shaped ones
error: OpenCV(4.9.0) /io/opencv/modules/imgproc/src/thresh.cpp:1675: error: (-215:Assertion failed) blockSize % 2 == 1 && blockSize > 1 in function 'adaptiveThreshold'error                                     Traceback (most recent call last)
Cell In[34], line 2
      1 # First, detect the color card.
----> 2 card_mask = pcv.transform.detect_color_card(rgb_img=crop_img, adaptive_method=0, radius=15, block_size=10)
      4 # Print average chip size, value is stored in outputs.observations
      5 #print(pcv.outputs.observations['B73']['median_color_chip_size']['value'])
File ~/.local/lib/python3.9/site-packages/plantcv/plantcv/transform/detect_color_card.py:69, in detect_color_card(rgb_img, label, **kwargs)
     67 imgray = cv2.cvtColor(rgb_img, cv2.COLOR_BGR2GRAY)
     68 gaussian = cv2.GaussianBlur(imgray, (11, 11), 0)
---> 69 thresh = cv2.adaptiveThreshold(gaussian, 255, adaptive_method,
     70                                cv2.THRESH_BINARY_INV, block_size, 2)
     71 contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
     73 # Filter contours, keep only square-shaped ones
error: OpenCV(4.9.0) /io/opencv/modules/imgproc/src/thresh.cpp:1675: error: (-215:Assertion failed) blockSize % 2 == 1 && blockSize > 1 in function 'adaptiveThreshold'
@HaleySchuhl HaleySchuhl added the new feature New feature ideas and solutions label Jan 16, 2024
@HaleySchuhl HaleySchuhl added this to New Issues in PlantCV4 via automation Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature ideas and solutions
Projects
PlantCV4
  
New Issues
Development

No branches or pull requests

1 participant