'How to send Frame from openCV client to server

I am trying to send input from a capture card on a client to a server. I can get the capture card to display on the client, but I am having some trouble sending the frames to the server to be shown.

This handles showing the frames within a jframe on the client:

    while (true)
    {
        if (camera.read(frame))
        {
            
            ImageIcon image = new ImageIcon(matToBufferedImage(frame));
            vidpanel.setIcon(image);
            vidpanel.repaint();                
        }
    }

If I try to send just an image from a client to the server I can make that work:

Server

    ServerSocket serverSocket = new ServerSocket(9090);
    Socket socket = serverSocket.accept();
    System.out.println("CLIENT CONNECTED!");
    InputStream input = socket.getInputStream();
    BufferedInputStream bufferedInput = new BufferedInputStream(input);
    BufferedImage bufferedImage = ImageIO.read(bufferedInput);
    bufferedInput.close();
    socket.close();
    JLabel jlabel = new JLabel(new ImageIcon(bufferedImage));
    text.setText("RECIEVED");
    jframe.add(jlabel, BorderLayout.CENTER);

Sending the image from the client:

    ImageIcon imageIcon = new ImageIcon("/pathtoimage/Untitled.png");
    JLabel pic = new JLabel(imageIcon);
    JButton button = new JButton("SEND");
            
    jframe.add(pic,BorderLayout.CENTER);
    jframe.add(button,BorderLayout.SOUTH);
            
            
    jframe.setVisible(true);
    
    OutputStream output = socket.getOutputStream();
    BufferedOutputStream bufferedOutput = new BufferedOutputStream(output);
    
    Image image = imageIcon.getImage();
    
    BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null),BufferedImage.TYPE_INT_RGB);
    
    Graphics graphics = bufferedImage.createGraphics();
    graphics.drawImage(image, 0,0,null);
    graphics.dispose();
    
    ImageIO.write(bufferedImage, "png", bufferedOutput);
    
    bufferedOutput.close();
    socket.close();

How could I adapt the first piece of code to be able to send unlimited frames to be rendered on the server?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source