Created
May 11, 2020 04:15
-
-
Save garybradski/6f2fe5212dd8b7c87243ac5fc7cdb2de to your computer and use it in GitHub Desktop.
Derivatives along a line in an image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def no_derivs(img, pt1,pt2,thresh=10): | |
''' | |
Test whether there are no image derivatives > thresh between pt1 and pt2 | |
:param img: BGR opencv numpy image | |
:param pt1: first (x,y) point | |
:param pt2: second (x,y) point | |
:param thresh: no image differences > than this amount allowed | |
:return: True if no derivs, else False | |
''' | |
coords = np.around(np.linspace(pt1, pt2, np.linalg.norm(pt1 - pt2))).astype(int) | |
vals = np.empty([len(coords), 3], dtype=int) | |
for i, p in zip(range(len(coords)),coords): | |
vals[i] = img[p[1],p[0]] | |
maxd = np.max(np.fabs(vals[0:-1] - vals[1:])) | |
if maxd < thresh: | |
return True | |
else: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment