Results 1 to 2 of 2
  1. #1
    trump is offline Member
    Join Date
    Jul 2012
    Posts
    1
    Rep Power
    0

    Exclamation From CanvasFrame to JPanel

    Hello from Russia!
    I'm new in Java and stopped in one thing!

    Example: I want to have 4 rtsp video in one JFrame and all video exlode for own thread.
    Need!: Create class that make JPanel with rtsp video that i can copy and insert over source of video. Then i put all of this JPanel on my JFrame.

    I have this code:
    Java Code:
    import static com.googlecode.javacv.cpp.opencv_core.CV_AA;  
    import static com.googlecode.javacv.cpp.opencv_core.IPL_DEPTH_8U;  
    import static com.googlecode.javacv.cpp.opencv_core.cvGetSeqElem;  
    import static com.googlecode.javacv.cpp.opencv_core.cvLoad;  
    import static com.googlecode.javacv.cpp.opencv_core.cvPoint;  
    import static com.googlecode.javacv.cpp.opencv_core.cvRectangle;  
    import static com.googlecode.javacv.cpp.opencv_highgui.cvLoadImage;  
    import static com.googlecode.javacv.cpp.opencv_highgui.cvSaveImage;  
    import static com.googlecode.javacv.cpp.opencv_imgproc.CV_BGR2GRAY;  
    import static com.googlecode.javacv.cpp.opencv_imgproc.cvCvtColor;  
    import static com.googlecode.javacv.cpp.opencv_objdetect.cvHaarDetectObjects;  
      
    import com.googlecode.javacv.cpp.opencv_core.CvMemStorage;  
    import com.googlecode.javacv.cpp.opencv_core.CvRect;  
    import com.googlecode.javacv.cpp.opencv_core.CvScalar;  
    import com.googlecode.javacv.cpp.opencv_core.CvSeq;  
    import com.googlecode.javacv.cpp.opencv_core.IplImage;  
    import com.googlecode.javacv.cpp.opencv_objdetect.CvHaarClassifierCascade;
    
    import com.googlecode.javacpp.Loader;
    import com.googlecode.javacv.*;
    import static com.googlecode.javacv.cpp.opencv_core.*;
    import static com.googlecode.javacv.cpp.opencv_imgproc.*;
    import static com.googlecode.javacv.cpp.opencv_calib3d.*;
    import com.googlecode.javacv.cpp.opencv_highgui;
    import static com.googlecode.javacv.cpp.opencv_objdetect.*;
    
    public class FaceRTSP {
        public static void main(String[] args) throws Exception {
            /*
             * rtsp://ss1c6.idc.mundu.tv:554/prf0/cid_4.sdp –aajtak 
                rtsp://ss1c6.idc.mundu.tv:554/prf0/cid_2.sdp - times now
                rtsp://ss1c6.idc.mundu.tv:554/prf0/cid_7.sdp -headlines today
                rtsp://ss1c6.idc.mundu.tv:554/prf0/cid_29.sdp -ndtv 24*7
                rtsp://ss1c6.idc.mundu.tv:554/prf0/cid_31.sdp - ndtv profit
                rtsp://ss1c6.idc.mundu.tv:554/prf0/cid_32.sdp - ndtv goodtimes
                rtsp://ss1c6.idc.mundu.tv:554/prf0/cid_33.sdp - ndtv india
                rtsp://ss1c6.idc.mundu.tv:554/prf1/cid_34.sdp -cnbc awaaz
                rtsp://ss1c6.idc.mundu.tv:554/prf0/cid_35.sdp - cnbc Tv18
                rtsp://121.244.145.226:554/prf0/cid_45.sdp - zee business
                rtsp://121.244.145.226:554/prf0/cid_38.sdp - zee marathi
                rtsp://121.244.145.226:554/prf0/cid_41.sdp -zee tv
                rtsp://121.244.145.226:554/prf0/cid_50.sdp - zee regional
                rtsp://121.244.145.226:554/prf0/cid_52.sdp - zee regional
                rtsp://121.244.145.226:554/prf0/cid_54.sdp - zee regional
                rtsp://121.244.145.226:554/prf0/cid_55.sdp - zee regional
                rtsp://121.244.145.226:554/prf0/cid_61.sdp - ten action
                rtsp://121.244.145.226:554/prf0/cid_62.sdp - etc
                rtsp://121.244.145.226:554/prf0/cid_56.sdp - zing
                rtsp://121.244.145.226:554/prf0/cid_57.sdp -zee classic
                rtsp://121.244.145.226:554/prf0/cid_58.sdp zee smile
             */
            //rtsp://62.149.26.237:1935/tv/_definst_/ntn
            //rtsp://62.149.26.237:1935/tv/_definst_/k1
            //rtsp://iptv.karelia.ru/ort.sdp
            OpenCVFrameGrabber grabber = new OpenCVFrameGrabber("rtsp://62.149.26.237:1935/tv/_definst_/inter");
            grabber.start();
    
            IplImage image = grabber.grab();
    
    
            CanvasFrame canvasFrame = new CanvasFrame("Web Cam Detection Going on");
            canvasFrame.setCanvasSize(image.width(), image.height());
            canvasFrame.setDefaultCloseOperation(CanvasFrame.EXIT_ON_CLOSE);
            while (true) {
                IplImage originalImage = grabber.grab();
                canvasFrame.showImage(originalImage);
            }
    
        }
    
    }
    It's example that create JFrame. People sad that i need to make jLabel(new ImageIcon( originalImage.getBufferedImage() ), but it don't work:

    Java Code:
    import static com.googlecode.javacv.cpp.opencv_core.CV_AA;  
    import static com.googlecode.javacv.cpp.opencv_core.IPL_DEPTH_8U;  
    import static com.googlecode.javacv.cpp.opencv_core.cvGetSeqElem;  
    import static com.googlecode.javacv.cpp.opencv_core.cvLoad;  
    import static com.googlecode.javacv.cpp.opencv_core.cvPoint;  
    import static com.googlecode.javacv.cpp.opencv_core.cvRectangle;  
    import static com.googlecode.javacv.cpp.opencv_highgui.cvLoadImage;  
    import static com.googlecode.javacv.cpp.opencv_highgui.cvSaveImage;  
    import static com.googlecode.javacv.cpp.opencv_imgproc.CV_BGR2GRAY;  
    import static com.googlecode.javacv.cpp.opencv_imgproc.cvCvtColor;  
    import static com.googlecode.javacv.cpp.opencv_objdetect.cvHaarDetectObjects;  
      
    import com.googlecode.javacv.cpp.opencv_core.CvMemStorage;  
    import com.googlecode.javacv.cpp.opencv_core.CvRect;  
    import com.googlecode.javacv.cpp.opencv_core.CvScalar;  
    import com.googlecode.javacv.cpp.opencv_core.CvSeq;  
    import com.googlecode.javacv.cpp.opencv_core.IplImage;  
    import com.googlecode.javacv.cpp.opencv_objdetect.CvHaarClassifierCascade;
    
    import com.googlecode.javacpp.Loader;
    import com.googlecode.javacv.*;
    import com.googlecode.javacv.FrameGrabber.Exception;
    import static com.googlecode.javacv.cpp.opencv_core.*;
    import static com.googlecode.javacv.cpp.opencv_imgproc.*;
    import static com.googlecode.javacv.cpp.opencv_calib3d.*;
    import com.googlecode.javacv.cpp.opencv_highgui;
    import static com.googlecode.javacv.cpp.opencv_objdetect.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.ImageIcon;
    import javax.swing.JLabel;
    /**
     *
     * @author 7я
     */
    public class ChPanel extends javax.swing.JPanel {
    
        /**
         * Creates new form ChPanel
         */
        public ChPanel() {
            initComponents();
        }
    
        
        /**
         * This method is called from within the constructor to initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is always
         * regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
    
            jLabel1 = new javax.swing.JLabel();
            jButton1 = new javax.swing.JButton();
    
            jLabel1.setText("jLabel1");
    
            jButton1.setText("jButton1");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
            this.setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jButton1)
                    .addGap(131, 131, 131))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(0, 0, Short.MAX_VALUE)
                            .addComponent(jButton1))
                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE))
                    .addContainerGap())
            );
        }// </editor-fold>
    
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            try {
                OpenCVFrameGrabber grabber = new OpenCVFrameGrabber("rtsp://62.149.26.237:1935/tv/_definst_/inter");
                grabber.start();
                IplImage image = grabber.grab();
                while (true) {
                    IplImage originalImage = grabber.grab();
                    jLabel1.setIcon(new ImageIcon( originalImage.getBufferedImage() ));
                }
            } catch (Exception ex) {
                Logger.getLogger(ChPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JLabel jLabel1;
        // End of variables declaration
    }
    Help me!

  2. #2
    Rakesh Bhatt is offline Member
    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Thumbs up Re: From CanvasFrame to JPanel

    You can just create a new thread and in that thread you can put this code then it will surly work. You need to place the code to draw image on Label in separate thread
    like this
    class newThread implements Runnable
    {
    JLabel newLable;
    public newThread(JLabel jl)
    {
    newLabel=jl;
    }
    public void run()
    {
    try {
    OpenCVFrameGrabber grabber = new OpenCVFrameGrabber("rtsp://62.149.26.237:1935/tv/_definst_/inter");
    grabber.start();
    IplImage image = grabber.grab();
    while (true) {
    IplImage originalImage = grabber.grab();
    newLabel.setIcon(new ImageIcon( originalImage.getBufferedImage() ));
    }
    } catch (Exception ex) {
    Logger.getLogger(ChPanel.class.getName()).log(Leve l.SEVERE, null, ex);
    }
    }
    }
    }
    and then you can send create a this class and start this thread inside your actionPerformed function like this
    newThread ab=new newThread(jLabel1)
    Thread w=new Thread(ab);
    ab.start();

    That's all

Similar Threads

  1. Replies: 1
    Last Post: 12-13-2011, 03:38 AM
  2. Change JPanel text of Parent JPanel from JDialog
    By bikashlama in forum AWT / Swing
    Replies: 7
    Last Post: 12-09-2011, 04:47 AM
  3. Adding a jpanel to a customized Jpanel Class
    By trishtren in forum AWT / Swing
    Replies: 7
    Last Post: 04-05-2011, 07:52 PM
  4. Placing a new JPanel over a paint overriden JPanel
    By Tanshaydar in forum AWT / Swing
    Replies: 4
    Last Post: 12-08-2010, 07:00 PM
  5. Replies: 3
    Last Post: 04-21-2009, 12:31 AM

Tags for this Thread

Posting Permissions

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