Skip to content

Commit

Permalink
Opencv version checker added
Browse files Browse the repository at this point in the history
  • Loading branch information
PennyHow committed Jan 19, 2022
1 parent ad99137 commit 4849cef
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions PyTrx/Area.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import numpy as np
import cv2, ogr, unittest
from PIL import Image
from packaging import version

#Import PyTrx functions and classes
from PyTrx.FileHandler import readMask
Expand Down Expand Up @@ -560,9 +561,11 @@ def calcAutoArea(img, imn, colourrange, hmatrix=None, threshold=None,
# #Speckle filter to remove noise - needs fixing
# mask = cv2.filterSpeckles(mask, 1, 30, 2)

#Polygonize extents using OpenCV findContours function
i, line, hier = cv2.findContours(mask,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) #OpenCV v3.4.17 and lower
# line, hier = cv2.findContours(mask,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) #OpenCV v4 and higher
#Polygonize extents using OpenCV findContours function
if version.parse(cv2.__version__) > version.parse("3.4.17"):
line, hier = cv2.findContours(mask,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) #OpenCV v4 and higher
else:
i, line, hier = cv2.findContours(mask,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) #OpenCV v3.4.17 and lower

print('\nDetected ' + str(len(line)) + ' regions in ' + str(imn))

Expand Down

0 comments on commit 4849cef

Please sign in to comment.