远程计算机在使用网络摄像头sarxos API时打开我的网络摄像头

时间:2019-09-24 14:58:26

标签: java barcode webcam capture reader

我已使用Sarxos /网络摄像头捕获API来显示网络摄像头并扫描条形码。尽管当我将其部署在服务器计算机上或尝试从其他计算机上打开本地计算机的url时,单击该计算机上的照相机图标,它正在打开我机器中的网络摄像头面板和摄像头。

我正在使用罐子

webcam-capture0.3.12.jar and bridj 0.7.0.jar.

请帮助我为什么会发生这种情况以及解决方案。

下面是我正在使用的代码。

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.net.InetAddress;
import java.util.concurrent.ExecutionException;

import javax.swing.JFrame;

import com.fourcs.clm.fw.log.CLMLogManager;
import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamPanel;
import com.github.sarxos.webcam.WebcamResolution;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.NotFoundException;
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;

public class CopyOfWebcamQrCodeTesting extends JFrame  {

    private static final long serialVersionUID = 1L;

    private Webcam webcam = null;
    private WebcamPanel webcamPanel = null;
    private Result result = null;
    private boolean cancelled = false;
    private JFrame window  =null;
    public void testWebcamCode1(String remoteAddress) throws ExecutionException {
        try{
            System.out.println("Before layout");
        setLayout(new FlowLayout());
        System.out.println("After layout");
        Dimension size = WebcamResolution.QVGA.getSize();
        System.out.println("After size");
        InetAddress localhost = InetAddress.getLocalHost(); 
        System.out.println("System IP Address : " + 
                      (localhost.getHostAddress()).trim()); 
        System.out.println("remoteaddress:"+remoteAddress);

        if (!Webcam.getWebcams().isEmpty()) {
                webcam = Webcam.getWebcams().get(0);
                System.out.println("After webcam");
                System.out.println("webcam.getname():"+webcam.getName());
                webcam.setViewSize(size);
                System.out.println("webcam.getname():"+webcam.getName());


                webcamPanel = new WebcamPanel(webcam);
                webcamPanel.setFPSDisplayed(true);
                webcamPanel.setDisplayDebugInfo(true);
                webcamPanel.setImageSizeDisplayed(true);
                webcamPanel.setMirrored(true);
                System.out.println("After webpanel");
                 window = new JFrame("Test webcam panel");
                 System.out.println("After jframe");
                 window.setLayout(new FlowLayout());
                 window.setPreferredSize(new Dimension(320, 300));
                 window.add(webcamPanel);
                 window.setResizable(true);

                 window.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent evt) {
                            cancelled = true;
                            window.setVisible(false);
                        }
                    });
                 window.pack();
                 window.setLocationRelativeTo(null);
                 window.setVisible(true);


                test11();

              }else{
                 System.out.println("Webcam Not found.Please try in another machine which is having webcam");
             }

         /*Thread t = new Thread() {
                @Override
                public void run() {
                    webcamPanel.start();

                }
            };
            t.setName("example-starter");
            t.setDaemon(true);
            t.start();
        */
        }catch(Exception e){
            CLMLogManager.Log(getClass().getName(), CLMLogManager.LOG_ERROR, e.getMessage(), e);
        }

    }

    private void test11() {
        do {
            System.out.println("cancelled value:"+cancelled);

            BufferedImage image = null;
            //if (webcam.isOpen() ) {
                image = webcam.getImage();
                int width =0;
                int height =0;
                if(image!=null){
                 width = image.getWidth();
                 height = image.getHeight();
                }
                BufferedImage cropedImage = image.getSubimage(0, 0, width,
                        height);
                LuminanceSource source = new BufferedImageLuminanceSource(
                        cropedImage);
                BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(
                        source));

                try {
                    result = new MultiFormatReader().decode(bitmap);

                } catch (NotFoundException e) {
                }
            //}
            if (result != null) {
                try{
                System.out.println("vin is:" + result.getText());
                //product.setProductSerialNum(result.getText());
                //claimHelper.setNewProductSerialNumber(result.getText());
                } finally {
                    webcam.close();
                    setVisible(false);
                    window.setVisible(false);
                }


            }else if(cancelled==true){
                webcam.close();
                webcamPanel.stop();
                setVisible(false);
                webcamPanel.setVisible(false);

                window.setVisible(false);
            }

        } while (result == null && cancelled==false);

    }


    /*public static void main(String[] args) throws ExecutionException {
        new CopyOfWebcamQrCodeTesting().testWebcamCode1();
    }
*/
}

0 个答案:

没有答案