shaileshmulange / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

[0.1] Different rendering between JavaCV and C-OpenCV #209

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Comparing the result of the following code snipplets :

Scala+JavaCV code :
object Main extends App{
val image = cvLoadImage("/home/rom1dep/tiger.jpg",CV_LOAD_IMAGE_UNCHANGED)
val canvas1 = new CanvasFrame("My Image")
canvas1.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE)
canvas1.showImage(image)
}

C code :
int main() {
    cv::Mat image = cv::imread("/home/rom1dep/tiger.jpg");
    cv::namedWindow("My Image");
    cv::imshow("My Image", image);
    cv::waitKey(50000);//scrshot huw :)

    return 1;
}

Result as a screenshot attached

What is the expected output? What do you see instead?

upper-left image : JavaCV
upper-right : reference image
bottom : C

Those 3 images should be the same (I guess ?)

What version of the product are you using? On what operating system?

JavaCV-bin from the «Downloads» tab (0.1)
same result with openjdk and oracle's jdk
OpenCV 2.4.1 (compiled)
Linux x86_64 (fedora 17)

I had a quick look at the Issues and found nothing like this, sorry if it's a 
duplicate.

Original issue reported on code.google.com by rom1dep on 18 Jun 2012 at 11:13

GoogleCodeExporter commented 9 years ago
OpenCV doesn't do gamma correction, so if you're expecting the same behavior 
from CanvasFrame, that is your images are already gamma corrected, create one 
with something like `new CanvasFrame("My Image", 1.0)` as shown in the 
README.txt file. Does that do you what you want?

Original comment by samuel.a...@gmail.com on 19 Jun 2012 at 1:25

GoogleCodeExporter commented 9 years ago
Indeed, that do the trick,
thanks for your quick answer !

Actually I took this page¹ to get started with JavaCV, and saw nothing about 
gamma (while both sources to load images are said to do the same²). Maybe you 
can add some note about that on the wiki page to prevent other /dumb/ questions 
like mine ?

Thanks again and congrats for this great binding :)

Romain.

¹: http://code.google.com/p/javacv/wiki/OpenCV2_Cookbook_Examples
²: «The above C++ example translated to Scala using JavaCV wrapper:»

Original comment by rom1dep on 21 Jun 2012 at 9:31

GoogleCodeExporter commented 9 years ago
Oh I see, we'll notify Jarek about this... :) thanks!

Jarek, you may close once the example has been clarified, thanks!

Original comment by samuel.a...@gmail.com on 21 Jun 2012 at 9:34

GoogleCodeExporter commented 9 years ago
Thanks for pointing this out.

I do not see explanation of gamma argument to CanvasFrame in 
https://code.google.com/p/javacv/source/browse/README.txt

It is quite unusual that by default image is modified before display. 

I corrected examples in the Wiki to explicitly specify gamma=1, similar in the 
source code.

Original comment by jarek.li...@gmail.com on 22 Jun 2012 at 1:14

GoogleCodeExporter commented 9 years ago
Great, thanks!

It is unusual for desktop applications, but for computer vision, we usually 
need to work on images with linear intensities, so personally I think the right 
way is to apply gamma correction on these images by default.

Besides, Java considers gray images as linear by default:
http://docs.oracle.com/javase/6/docs/api/java/awt/image/BufferedImage.html#TYPE_
BYTE_GRAY

So, I'm merely doing it the Java way :)

Original comment by samuel.a...@gmail.com on 22 Jun 2012 at 8:57