Skip to content

Commit 4849cef

Browse files
committed
Opencv version checker added
1 parent ad99137 commit 4849cef

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

PyTrx/Area.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import numpy as np
1919
import cv2, ogr, unittest
2020
from PIL import Image
21+
from packaging import version
2122

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

563-
#Polygonize extents using OpenCV findContours function
564-
i, line, hier = cv2.findContours(mask,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) #OpenCV v3.4.17 and lower
565-
# line, hier = cv2.findContours(mask,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) #OpenCV v4 and higher
564+
#Polygonize extents using OpenCV findContours function
565+
if version.parse(cv2.__version__) > version.parse("3.4.17"):
566+
line, hier = cv2.findContours(mask,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) #OpenCV v4 and higher
567+
else:
568+
i, line, hier = cv2.findContours(mask,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) #OpenCV v3.4.17 and lower
566569

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

0 commit comments

Comments
 (0)