Results 1 to 4 of 4
Thread: Webcam Images and Transparency
- 02-15-2012, 04:38 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 6
- Rep Power
- 0
Webcam Images and Transparency
Is that anyone know how to remove the images background to transparency??
The ideas I use is after click capture the images had been taken will just focus on the people faces and all the background will be transparent.
I had been success create a webcam code and display the images but I failed to remove the images background~~is that anyone can help me and gave me some hint???
How to turn the background to transparent???
Java Code:import javax.swing.*; import javax.swing.JFrame; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.media.Buffer; import javax.media.Manager; import javax.media.MediaLocator; import javax.media.Player; import javax.media.control.FrameGrabbingControl; import javax.media.format.VideoFormat; import javax.media.util.BufferToImage; public class Webcaming extends JFrame { private JPanel display = null; private JButton capturing = new JButton("Images Capture"); private Player player = null; private Buffer buf = null; private Image img = null; private BufferToImage btoi = null; public Webcaming(){ webCamComponent(); }//end WebCamTest() private void webCamComponent(){ setLayout(new GridLayout(0,3,5,5)); JFrame jfmDisplay = new JFrame("Display"); JPanel displaying = new JPanel(); Container details = jfmDisplay.getContentPane(); jfmDisplay.setSize(1000,1000); details.add(displaying); jfmDisplay.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel show = new JPanel(); show.setSize(400, 400); display = new JPanel(); show.add(display, BorderLayout.CENTER); add(show, BorderLayout.CENTER); getContentPane().add(display, BorderLayout.CENTER); JPanel buttonCap = new JPanel(); //buttonCap.setLayout(new GridLayout(0,3,5,5)); buttonCap.add(capturing, BorderLayout.NORTH); add(buttonCap, BorderLayout.CENTER); capturing.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent capBtn){ jButtonCapActionPerformed(capBtn); } }); pack(); setVisible(true); }//end webCamComponent private void jButtonCapActionPerformed(ActionEvent capBtn){ if(capBtn.getActionCommand().equals("Images Capture")){ JFrame jfmWebcam = new JFrame("Webcam"); jfmWebcam.setSize(320, 320); JButton capture = new JButton("Capture"); jfmWebcam.add(capture, BorderLayout.NORTH); //Button Event capture.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent captureBtn){ jButtonCaptureActionPerformed(captureBtn); }//end actionPerformed }); try{ MediaLocator webcamera = new MediaLocator("vfw://0"); player = Manager.createRealizedPlayer(webcamera); if(player.getVisualComponent()!=null){ jfmWebcam.getContentPane().add(player.getVisualComponent()); }//end if player.start(); jfmWebcam.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); jfmWebcam.pack(); jfmWebcam.setVisible(true); }//end try catch (Exception ex){ JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); }//end catch }//end if }//end jButtonCapActionPerformed private void jButtonCaptureActionPerformed(ActionEvent captureBtn){ if(captureBtn.getActionCommand().equals("Capture")){ if(player != null){ FrameGrabbingControl fgcFrame = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl"); buf = fgcFrame.grabFrame(); //convert it to an image btoi = new BufferToImage((VideoFormat)buf.getFormat()); img = btoi.createImage(buf); img = new ImageIcon(img).getImage(); //display.setIconImage(img); }//end if }//end if }//end jButtonCaptureActionPerformed public void paint(Graphics g){ g.drawImage(img, 0, 0, null); g.dispose(); } public static void main(String[] args) { Webcaming wct = new Webcaming(); }//end main }//end class
- 02-15-2012, 05:04 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,466
- Rep Power
- 16
Re: Webcam Images and Transparency
So you've captured the image, and have you identified which parts of the image you want to keep?
If so, and the image type allows for Alpha then set the alpha for all pixels that aren't your face.
- 02-15-2012, 05:14 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 6
- Rep Power
- 0
Re: Webcam Images and Transparency
emmm~~any example??
I have captured the image but how shd I identified the part of the image???
- 02-15-2012, 05:39 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,466
- Rep Power
- 16
Similar Threads
-
Transparency
By zirbinator in forum Java 2DReplies: 7Last Post: 03-28-2012, 05:51 AM -
DrawImage with transparency ?
By mrhid6 in forum AWT / SwingReplies: 2Last Post: 10-01-2011, 11:58 PM -
Filling with transparency
By zirbinator in forum Java 2DReplies: 3Last Post: 02-09-2011, 02:36 AM -
ImageIcon Transparency
By Lingerz in forum New To JavaReplies: 2Last Post: 06-04-2010, 02:53 PM -
capture webcam images with java
By MuslimCoder in forum Advanced JavaReplies: 3Last Post: 12-21-2009, 03:21 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks