Home Scaling Mat elements to [0..255] range with OpenCV on Android
Reply: 0

Scaling Mat elements to [0..255] range with OpenCV on Android

user1221 Published in August 16, 2018, 6:14 am

I am trying to convert some OpenCV python code to Java and I ran into a problem of finding the correct functions in Java wrapper. The python code in question is calculating the Scharr gradient along the x-axis as:

# compute the Scharr gradient of the blackhat image and scale the
# result into the range [0, 255]
gradX = cv2.Sobel(blackhat, ddepth=cv2.CV_32F, dx=1, dy=0, ksize=-1)
gradX = np.absolute(gradX)
(minVal, maxVal) = (np.min(gradX), np.max(gradX))
gradX = (255 * ((gradX - minVal) / (maxVal - minVal))).astype("uint8")

[Code is from pyimagesearch website - Detecting machine-readable zones in passport images - blog post]

What I have in Java is:

Imgproc.Sobel(blackhat, gradX, CvType.CV_32F, 1, 0, -1, 1.0, 0, Core.BORDER_DEFAULT);
Core.convertScaleAbs(gradX, gradX);
Core.MinMaxLocResult minmax = Core.minMaxLoc(gradX);

This should output the same result as the first three lines of the python code. But I got stuck on the last one. How does one perform the scaling of the gradX back into the [0..255] range with Java API?

Also does the convertScaleAbs function perform the same action as NumPys absolute?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.296792 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO