I need to develop an application using a MVC Design Pattern.
My doubt is how to insert the IplImage inside of JLabel or JPanel,
because i always, until now, work with CanvasFrame do display de
Images.
I saw some examples but i did not understood because i dont have
experience with GUI in JAVA.
Can you help me, urgently.
Menegussi
Samuel
Help me, please :)
André Menegussi
Well if you want to display the image in a JLabel, for example, we can call:
new JLabel(new ImageIcon(IplImage.getBufferedImage())
Samuel
labelTemp.repaint();
Samuel
On 2011-11-30 03:28, Andr� Menegussi wrote:
> Hi Samuel,
> I'm again!!
> How could i update the JLabel with news frames grabbed from the webcam?
> I tried to use the commands:
> *ImageIcon quadro = new*ImageIcon( frame.getBufferedImage());
Dear Srijit or anyone else..,
I did the Java-course at school about 10years ago and now I am ofcourse really tumbeling when I try to re-learn...
I tried your code below but without success, I would be really glad if someone could please help me out here, probably it is extremely simple..
My simple code looks like the following:
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;import com.googlecode.javacv.OpenCVFrameGrabber;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
public class javaVision extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;//bara frö att få bort ett felmeddelande från eclipse..
// 0-default camera, 1 - next...so on
OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(1);
IplImage IplImg = new IplImage();
JPanel prePanel = new JPanel();
JPanel postPanel = new JPanel();
JButton captureButton = new JButton("Capture");
public javaVision() {
initUI();
}
public final void initUI() {
Container contentPane = this.getContentPane();
contentPane.setLayout(new BorderLayout());
captureButton.setBounds(100, 60, 100, 30);
//Add action listener to button
captureButton.addActionListener(this);prePanel.setSize(640,480);
this.add(prePanel, BorderLayout.SOUTH);
this.add(captureButton, BorderLayout.NORTH);this.setTitle("Tooltip");
this.setSize(1024, 728);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
prePanel.setVisible(true);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if (cmd.equals("Capture")){
this.capture();
}
}
public void capture(){
try {
grabber.start();
IplImg = grabber.grab();
}
catch (Exception e) {
e.printStackTrace();
}
BufferedImage BufImg = IplImg.getBufferedImage();
int w = BufImg.getWidth();
int h = BufImg.getHeight();
System.out.println("width: "+w);
System.out.println("height: "+h);
//BOTH THE IPLIMG AND THE BUFIMG CONTAINS CORRECT INFO , tried to save to file with ´both of them. The fault is probably on the following 4 lines..
Graphics g = BufImg.getGraphics();
Graphics2D g2 = (Graphics2D) g.create();
prePanel.paintComponents(g2);
g2.drawImage(BufImg, 0, 0, w, h, null);
//g2.drawLine(10, 10, 50, 50);//THIS DOESNT WORK EITHER
prePanel.repaint();
this.repaint();
try {
grabber.stop();
} catch (com.googlecode.javacv.FrameGrabber.Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
javaVision ex = new javaVision();
ex.setVisible(true);
}
});
}}
--
---
You received this message because you are subscribed to a topic in the Google Groups "javacv" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/javacv/AJIR6CfHHYg/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to javacv+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
---
You received this message because you are subscribed to the Google Groups "javacv" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javacv+un...@googlegroups.com.