Page 1 of 2 12 LastLast
Results 1 to 20 of 32

Thread: Image Tagging

  1. #1
    techack is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Image Tagging

    I'm new to Java and want to design an Image Tagging application.

    I have already started off with some code but now facing problem in Drawing a Rectangular box (for tagging) and getting the coordinates of the entire tag and saving them along with $TagName in a file.

    It would be great if someone could help me out with the code. Since, I have already done some of the code, if anyone can just look into it and add the above functionality, please post here and I can send u my code

    Thanks a lot!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Image Tagging

    If you want help with your code, post it here with your questions or problems.

  3. #3
    techack is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Re: Image Tagging

    I have created the JfileChooser. On which control should I display the image? (Do I have to use Canvas?) Currently I'm displaying the image using:
    Java Code:
    JLabel picLabel = new JLabel(new ImageIcon( bi ));
    But I want to draw rectangular tags in it(similar to Facebook tagging) and save the coordinates in a file. I would be grateful if someone could help me out with the code of above two functionality. Thanks a lot!


    Java Code:
    JFileChooser fc = new JFileChooser();
                int returnVal = fc.showOpenDialog(frame);
    
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File selectedFile = fc.getSelectedFile();
    				System.out.println(selectedFile.getPath());
    				try {
    					bi = ImageIO.read(selectedFile);
    					
    					JLabel picLabel = new JLabel(new ImageIcon( bi ));
    					imgpanel.add(picLabel);
    				} catch (IOException e1) {
    					// TODO Auto-generated catch block
    					e1.printStackTrace();
    				}

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Image Tagging

    I want to draw rectangular tags
    If you get a Graphics object from the BufferedImage (I assume that is what bi is) the Graphics class has methods for drawing.
    save the coordinates in a file
    For writing data to a file, what kind of data do you want to write? Binary, text, ???

    If you'll post your code, we'll help you get your code to work.

  5. #5
    techack is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Re: Image Tagging

    Norm, thanks a lot for your prompt reply.
    Can u PM me your E-Mail, I will send the set of class files and you can help me.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Image Tagging

    Sorry, I do all my work for code posted on the forum. If you want help, post the code here.

  7. #7
    techack is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Re: Image Tagging

    Here goes the code.

    Currently the image is not being displayed as soon as I select it from JFileChooser. Please suggest the correction for the Bug.
    Also, kindly provide me with code for creating rectangular tags and saving it in a file.

    Thanks a lot Norm..!!

    Java Code:
    public class MyProg extends JPanel implements ActionListener {
    
    	JTextArea whitebox;
    	static BufferedImage bi;
    	static JFrame frame = new JFrame(" Image Protection ");
    	JPanel imgpanel = new JPanel();
    	
    	public JPanel createContentPane()
        {	//Create Swing GUI Widgets here
            JPanel totalGUI = new JPanel();
            totalGUI.setMinimumSize(new Dimension(300, 200));
            totalGUI.setPreferredSize(new Dimension(300, 600));
                    
                   
    	    imgpanel.setLocation(0,0);
    	    //imgpanel.add();
    	   
    	    totalGUI.add(imgpanel);
                    
            whitebox = new JTextArea();
            whitebox.setEditable(false);
            whitebox.setLineWrap(true);
            whitebox.setWrapStyleWord(true);
            whitebox.setMinimumSize(new Dimension(300, 200));
            whitebox.setPreferredSize(new Dimension(200, 200));
            totalGUI.add(whitebox);
            
            totalGUI.setOpaque(true);
            return totalGUI;
        }
    
        public JMenuBar createMenuBar()
        {
            //Create the menu bar.
            JMenuBar menuBar = new JMenuBar();
    
            //Add a JMenu
            JMenu fileMenu = new JMenu("File");
            JMenu imageMenu = new JMenu("Image");
            JMenu helpMenu = new JMenu("Help"); 
    
            menuBar.add(fileMenu);
            menuBar.add(imageMenu);
            menuBar.add(helpMenu);
            
            // Now we want to fill each of the menus.
                    
            JMenuItem dirChooser = new JMenuItem("Choose Directory");
            dirChooser.addActionListener(this);
            JMenuItem exit = new JMenuItem("Exit");
            exit.addActionListener(this);
            
            fileMenu.add(dirChooser);
            fileMenu.add(exit);
     
    		// Image Menu
    		JMenuItem tagIt =  new JMenuItem("Tag It");
    		tagIt.addActionListener(this);
            JMenuItem saveTag = new JMenuItem("Save Tag");
            
            imageMenu.add(tagIt);
            imageMenu.add(saveTag);
    				  
            // helpMenu
    		JMenu help = new JMenu("Help");
            JMenuItem about =  new JMenuItem("About");
            
            helpMenu.add(about);
    	   
            return menuBar;
        }
    
        private static void createAndShowGUI() {
    
            JFrame.setDefaultLookAndFeelDecorated(true);
           // JFrame frame = new JFrame(" Image Protection ");
    
            //Create and set up the content pane.
            MyProg demo = new MyProg();
            frame.setContentPane(demo.createContentPane());
            // We now also set the MenuBar of the Frame to our MenuBar 
            frame.setJMenuBar(demo.createMenuBar());
    
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
        }
    
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
            
     
            
        }
    
    	@Override
    	public void actionPerformed(ActionEvent e) {
    		whitebox.append(e.getActionCommand() + " Selected \n");
    		
    		if(e.getActionCommand() == "Choose Directory")
    		{
                JFileChooser fc = new JFileChooser();
                fc.addChoosableFileFilter(new ImageFilter());
                fc.setFileView(new ImageFileView());
                fc.setAccessory(new ImagePreview(fc));
    
                int returnVal = fc.showOpenDialog(frame);
    
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File selectedFile = fc.getSelectedFile();
    				System.out.println(selectedFile.getPath());
    				try {
    					bi = ImageIO.read(selectedFile);
    					
    					JLabel picLabel = new JLabel(new ImageIcon( bi ));
    					imgpanel.add(picLabel);
    					//frame.add(picLabel);
    				} catch (IOException e1) {
    					// TODO Auto-generated catch block
    					e1.printStackTrace();
    				}
                    
                } else if(returnVal == JFileChooser.CANCEL_OPTION) 
    			{
    				System.out.println("cancelled");
    			}
            }
    }

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Image Tagging

    You don't seem to be redrawing the imgpanel.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Image Tagging

    Please define what a "rectangular tag" is.
    Last edited by Norm; 01-03-2012 at 05:08 PM.

  10. #10
    techack is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Re: Image Tagging

    Can you put up the code to
    1. Display the image in the panel.
    2. Enable user to draw rectangles and tag them with $TagName (As there is photo tagging in Facebook)
    3. Save these tags alongwith the coordinates in the same directory with the same <filename>.jpg.tagg

    Thanks..Also, kindly correct the above code if you there are some issues with it since I'm still in the learning phase...

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Image Tagging

    Sorry, we don't write code. We help students get their code to work.

    My version of your program displays an image.

  12. #12
    techack is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Re: Image Tagging

    Yeah, you don't write code but atleast you can suggest and make the above program work, since the image is not being DISPLAYED IMMEDIATELY after selecting the image through JFileChooser.
    I would really appreciate if u can write a function of draw tags and saving them because that is part I'm unable to deal with.

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Image Tagging

    Your posted code worked for me when I made this change to it. I commented out the JFileChooser and hardcoded the path to an image:
    Java Code:
                    File selectedFile = new File("http://www.java-forums.org/images/AppletImg.jpg"); //fc.getSelectedFile();
                    System.out.println(selectedFile.getPath());
                    try {
                        bi = ImageIO.read(selectedFile);
                         
                        JLabel picLabel = new JLabel(new ImageIcon( bi ));
                        imgpanel.add(picLabel);   // This works!!! Image is inserted to left of textarea
    a function of draw tags and saving them
    Can you describe what you are talking about in programming terms?

  14. #14
    techack is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Re: Image Tagging

    But the image is not loaded immediately when I use JFileChooser. Select an image through it and it won't be displayed. Try it out!

    I want to draw rectangles on the image (I hope you got the idea of photo tagging) and save their coordinates along with the Tag Names.
    I'm not sure how can I do this and if I should use JLabel for displaying image and if JLabel supports "drawing" of shapes.

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Image Tagging

    Did the image display for you when you made the changes I posted?

    I can't use your code because there are two classes used in it that I do not have:
    ImageFileView());
    ImagePreview(fc));



    How are you going to choose where the rectangle is to be drawn on the image?
    Will you prompt the user for x,y, width and height or use the mouse?

  16. #16
    techack is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Re: Image Tagging

    No, I did not make any changes. I want to use JFilechoser only and allow user to select an image from the file system.

    I want to Use Mouse (obviously, that would be more interactive!)

  17. #17
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Image Tagging

    Try my code for testing if ANY IMAGE will be displayed. Later you can change the code to allow the user to chose the image.

  18. #18
    techack is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Re: Image Tagging

    When I click File->Choose directory and select a file, no image is displayed. But as soon as I click File->Choose directory again, the image is displayed.
    Going by Toll's advice in the comment above I even tried,
    Java Code:
    imgpanel.repaint();
    at this location
    Java Code:
    try {
    					bi = ImageIO.read(selectedFile);
    					
    					JLabel picLabel = new JLabel(new ImageIcon( bi ));
    					imgpanel.add(picLabel);
    					imgpanel.repaint();
    					//frame.add(picLabel);
    				} catch (IOException e1) {
    					// TODO Auto-generated catch block
    					e1.printStackTrace();
    				}
    But it doesn't work

  19. #19
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Image Tagging

    as soon as I click File->Choose directory again, the image is displayed.
    That sounds like the GUI needs to refresh itself. If repaint doesn't work, try call validate() on the container holding the label with the image.

  20. #20
    techack is offline Member
    Join Date
    Jan 2012
    Posts
    16
    Rep Power
    0

    Default Re: Image Tagging

    I called frame.validate() and it worked..
    Can you help with the tagging part?

    Moderator please remove the redundant posts and merge it into one to make the problem description clear

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 07-28-2011, 08:48 AM
  2. Replies: 12
    Last Post: 04-14-2011, 01:58 PM
  3. Version tagging CVS repository files from Java or ANT
    By Kjartan in forum Advanced Java
    Replies: 5
    Last Post: 04-04-2011, 05:05 AM
  4. Replies: 14
    Last Post: 04-10-2009, 08:46 AM
  5. Replies: 0
    Last Post: 01-08-2008, 05:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •