1

I've got a Java program running OpenCV and I'm using the MatchTemplate function. I have an output Mat with values ranging from 0.0 to 1.0. I want to be able to track its output in real time by making this Mat into a grayscale image that I can display as a "heatmap" of where my template matches the input image.

I've converted the image to grayscale using convertTo as suggested in the answer to this question and I'm using a third-party library called ImShow to get my Mat objects to display onscreen. It's working for my source images but my output, the result of the matchTemplate function, just shows solid black.

I think the floating point values from 0.0 to 1.0 are being rounded down to 0. Can I multiply every pixel in this Mat by 255 in order to shift it into proper greyscale? How would I do that?

Community
  • 1
  • 1
dftba4ever
  • 125
  • 3
  • 11
  • Please refer to http://docs.opencv.org/java/2.4.2/org/opencv/highgui/Highgui.html#imwrite%28java.lang.String,%20org.opencv.core.Mat%29 . You can use imwrite. – zawhtut Mar 06 '15 at 17:20
  • Your original question was pretty broad and lacking in details. I've incorporated [your comment](http://stackoverflow.com/questions/28823623/opencv-how-do-i-display-a-mat-that-i-formed-from-output-of-matchtemplate#comment45956456_28839495) into the question to narrow its scope, but you should also show the code you're using that's not doing what you expect. – Air Mar 06 '15 at 19:24

1 Answers1

1

Without getting into the details of displaying a Mat in Java you can convert the image to grayscale using

convertTo http://docs.opencv.org/modules/core/doc/basic_structures.html#mat-convertto

see this answer: Change type of Mat object from CV_32F to CV_8U

Community
  • 1
  • 1
  • Okay, I got the conversion working. I'm using a third-party library called ImShow to get my Mat objects to display onscreen. It's working for my source images, but my output, the result of the matchTemplate function, just shows solid black. I think the floating point values from 0.0 to 1.0 are being rounded down to 0. How can I multiply every pixel in this Mat by 255 in order to shift it into proper greyscale? – dftba4ever Mar 03 '15 at 23:08
  • @dftba4ever by adding the third parameter in convertTo: Set it to 255.0. – Nick Weaver Oct 20 '16 at 21:41