Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. def abs_sobel_thresh(img, orient='x', sobel_kernel=3, thresh=(0,255)):
  2. # Convert to grayscale
  3. gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
  4. # Apply x or y gradient with the OpenCV Sobel() function
  5. # and take the absolute value
  6. if orient == 'x':
  7. abs_sobel = np.absolute(cv2.Sobel(gray, cv2.CV_64F, 1, 0))
  8. if orient == 'y':
  9. abs_sobel = np.absolute(cv2.Sobel(gray, cv2.CV_64F, 0, 1))
  10. # Rescale back to 8 bit integer
  11. scaled_sobel = np.uint8(255*abs_sobel/np.max(abs_sobel))
  12. # Create a copy and apply the threshold
  13. binary_output = np.zeros_like(scaled_sobel)
  14. # Here I'm using inclusive (>=, <=) thresholds, but exclusive is ok too
  15. binary_output[(scaled_sobel >= thresh[0]) & (scaled_sobel <= thresh[1])] = 1
  16.  
  17. # Return the result
  18. return binary_output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement