Displaying an image using JavaCV

1,831 views
Skip to first unread message

Shervin

unread,
Feb 19, 2010, 8:49:02 PM2/19/10
to javacv
Hi Samuel,

I know that you didn't want to create a cvShowImage() function because
you said that it is much more efficient to use Java's own Canvas
method that can include hardware acceleration for faster operation.
But I was wondering, can you please provide some simple code that show
how to do this best?

Such as a simple program that loads a JPG file using JavaCV and
displays it on the screen in the correct way. (Or maybe a simple
program that grabs a camera frame and displays that on the screen). If
you can put the code on this newsgroup or include it with JavaCV then
I'm sure it will help a lot of people to quickly use JavaCV.

Cheers,
Shervin.

Samuel Audet

unread,
Feb 19, 2010, 10:52:40 PM2/19/10
to jav...@googlegroups.com
On 2010-02-20 10:49, Shervin wrote:
> Such as a simple program that loads a JPG file using JavaCV and
> displays it on the screen in the correct way. (Or maybe a simple
> program that grabs a camera frame and displays that on the screen). If
> you can put the code on this newsgroup or include it with JavaCV then
> I'm sure it will help a lot of people to quickly use JavaCV.

Well, there is no any "correct way" to use JavaCV. People can use OpenCV
and Java as the always have, and simply use some of the helper methods
that I provide in JavaCV.. But if they want, they can also use special
functionality specific to JavaCV that I added because I found it useful
as generic abstractions, such as the CanvasFrame and FrameGrabber.. here
is a simple reference program using those to grab a frame and display it
FYI:

import name.audet.samuel.javacv.*;
public class SingleFrameGrabber {
public static void main(String[] args) throws Exception {
CanvasFrame frame = new CanvasFrame(false, "Single Frame");
FrameGrabber grabber = new OpenCVFrameGrabber(0);
grabber.start();
frame.showImage(grabber.grab());
grabber.stop();
}
}

Samuel

Imran Khan

unread,
Sep 11, 2012, 11:17:44 AM9/11/12
to jav...@googlegroups.com
You could use a canvas frame to create an image viewer:
CanvasFrame viewWindow = new CanvasFrame("Preview", grabbedframe.getGamma());

You'd have to replace grabbedframe.getGamma() with whatever you wanted to show I suppose.  Then you could have JButtons which execute functions when pressed.

Hope that helps some

Imran

On 10 September 2012 19:02, Padmavati <padmav...@gmail.com> wrote:
hello,
       
       please help me i want to display image as an input then perform an operations on it, like rotate,blur,zoom.Using javacv and i'm using netbeans,i have code executed but i should display in GUI.How to do i dont know.....

In panel one side input image it should be same and when we perform operations on it should display on other side of  the panel.help me.....


with regards,
padmavati

Padmavati

unread,
Sep 12, 2012, 8:14:41 AM9/12/12
to jav...@googlegroups.com

I have uploaded the code of face detection which detects the faces but not correctly....how to resize it and detect it correctly....




Thank you,

with regards,
Padmavati.
FaceDetection1.java

Padmavati

unread,
Sep 12, 2012, 8:21:31 AM9/12/12
to jav...@googlegroups.com

Hi Samuel,

I have attached a java code which does 4operations,in same way i should display using JavaCV in GUI and in same panel keeping the original same.help me...

ConvolveApp.java

Padmavati

unread,
Sep 12, 2012, 12:10:30 PM9/12/12
to jav...@googlegroups.com
Can i display two images on same window using Canvas frame or Jframe or Panel side by side?
I'm using JavaCV/OpenCV,Netbeans IDE and java coding ,the input image should be same and whatever the operations performed like rotation or zoom or blur or sharpen or edge detection should should be displayed on other side of the image.
Is it possible?help me...


with regards,
Padmavati.

Samuel Audet

unread,
Sep 15, 2012, 12:22:46 AM9/15/12
to jav...@googlegroups.com
I think you want something like a split pane:
http://docs.oracle.com/javase/tutorial/uiswing/components/splitpane.html

Samuel Audet

unread,
Sep 15, 2012, 12:24:52 AM9/15/12
to jav...@googlegroups.com
On 2012-09-12 21:14, Padmavati wrote:
> I have uploaded the code of face detection which detects the faces but
> not correctly....how to resize it and detect it correctly....

Does the Demo class in the README.txt file work "correctly"?

RAJ

unread,
Feb 4, 2013, 9:06:32 AM2/4/13
to jav...@googlegroups.com

No the demo class is not working properly..... getting the following error..

Exception in thread "main" com.googlecode.javacv.FrameGrabber$Exception: videoInput.getPixels() Error: Could not get pixels.

VIDEOINPUT SPY MODE!

SETUP: Looking For Capture Devices
SETUP: 0) 1.3M WebCam
SETUP: 1 Device(s) found


***** VIDEOINPUT LIBRARY - 0.1995 - TFW07 *****

SETUP: Setting up device 0
SETUP: 1.3M WebCam
SETUP: Couldn't find preview pin using SmartTee
SETUP: Capture callback set
SETUP: Device is setup and ready to capture.

    at com.googlecode.javacv.VideoInputFrameGrabber.grab(VideoInputFrameGrabber.java:163)
    at demo2.Demo2.main(Demo2.java:53)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)

Samuel Audet

unread,
Feb 9, 2013, 2:13:12 AM2/9/13
to jav...@googlegroups.com
On 02/04/2013 11:06 PM, RAJ wrote:
> No the demo class is not working properly..... getting the following error..
>
> Exception in thread "main" com.googlecode.javacv.FrameGrabber$Exception: videoInput.getPixels() Error: Could not get pixels.

Try to use OpenCVFrameGrabber instead.

Like I said, VideoInputFrameGrabber does not work on some machines for
some reason, but since it works fine here on my machine, it's not
possible for me to fix it.

Samuel
Reply all
Reply to author
Forward
0 new messages