WEBカメラ と Wiiリモコン と Bluetooth(ブルートゥース)

下記サイトより、wiiリモコンを操作するライブラリを取得してくる
http://code.google.com/p/wiiusej/
http://wiiusej.googlecode.com/files/wiiusej%200.12b.zip

ちなみに、このライブラリを使用した理由は、WiiremoteJ + bluecove だと
東芝製のBluetoothブルートゥース)スタックを使用したレシーバでの動作が出来なかった為!!!
っと言うか、javaの実装がtodoだらけでカラッポだった。

後は、カメラからの画像を取得する為
なんとかしてJMFを使える様にする

public class Main
{
    /**
     * height
     */
    public static int APPLICATION_HEIGHT = 480;

    /**
     * width
     */
    public static int APPLICATION_WIDTH = 640;

    /**
     * @param args
     * @throws IOException
     * @throws CannotRealizeException
     * @throws NoPlayerException
     */
    public static void main(final String[] args) throws NoPlayerException,
            CannotRealizeException,
            IOException
    {
        final JFrame frame = new JFrame("test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(APPLICATION_WIDTH, APPLICATION_HEIGHT);

        final Player player = Manager.createRealizedPlayer(new MediaLocator(
                "vfw://0"));

        frame.getContentPane()
            .add(player.getVisualComponent());

        final FrameGrabbingControl grabbingControl = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");

        final Wiimote wiimote = WiiUseApiManager.getWiimotes(1, true)[0];
        wiimote.activateMotionSensing();
        wiimote.addWiiMoteEventListeners(new WiimoteListener()
        {

            @Override
            public void onButtonsEvent(final WiimoteButtonsEvent arg0)
            {
                // TODO 自動生成されたメソッド・スタブ

            }

            @Override
            public void onClassicControllerInsertedEvent(final ClassicControllerInsertedEvent arg0)
            {
                // TODO 自動生成されたメソッド・スタブ

            }

            @Override
            public void onClassicControllerRemovedEvent(final ClassicControllerRemovedEvent arg0)
            {
                // TODO 自動生成されたメソッド・スタブ

            }

            @Override
            public void onDisconnectionEvent(final DisconnectionEvent arg0)
            {
                // TODO 自動生成されたメソッド・スタブ

            }

            @Override
            public void onExpansionEvent(final ExpansionEvent arg0)
            {
                // TODO 自動生成されたメソッド・スタブ

            }

            @Override
            public void onGuitarHeroInsertedEvent(final GuitarHeroInsertedEvent arg0)
            {
                // TODO 自動生成されたメソッド・スタブ

            }

            @Override
            public void onGuitarHeroRemovedEvent(final GuitarHeroRemovedEvent arg0)
            {
                // TODO 自動生成されたメソッド・スタブ

            }

            @Override
            public void onIrEvent(final IREvent arg0)
            {
                // TODO 自動生成されたメソッド・スタブ

            }

            @Override
            public void onMotionSensingEvent(final MotionSensingEvent event)
            {
                final GForce g = event.getGforce();
                final float x = Math.abs(g.getX());
                final float y = Math.abs(g.getY());
                final float z = Math.abs(g.getZ());

                if (x > 4 || y > 4 || z > 4)
                {
                    final Buffer buffer = grabbingControl.grabFrame();
                    final BufferToImage exchanger = new BufferToImage(
                            (VideoFormat) buffer.getFormat());
                    final Image image = exchanger.createImage(buffer);
                    final BufferedImage bufferedImage = new BufferedImage(
                            APPLICATION_WIDTH, APPLICATION_HEIGHT,
                            Image.SCALE_SMOOTH);
                    bufferedImage.getGraphics()
                        .drawImage(image, 0, 0, Color.white, null);

                    try
                    {
                        ImageIO.write(bufferedImage, "jpeg", new File(
                                "/out/0.jpeg"));
                    }
                    catch (final IOException e)
                    {
                        e.printStackTrace();
                    }

                    System.exit(0);
                }
            }

            @Override
            public void onNunchukInsertedEvent(final NunchukInsertedEvent arg0)
            {
                // TODO 自動生成されたメソッド・スタブ

            }

            @Override
            public void onNunchukRemovedEvent(final NunchukRemovedEvent arg0)
            {
                // TODO 自動生成されたメソッド・スタブ

            }

            @Override
            public void onStatusEvent(final StatusEvent arg0)
            {
                // TODO 自動生成されたメソッド・スタブ

            }
        });

        frame.setVisible(true);
        player.start();
    }
}

そして、こんなコードを書いてみる。

カメラからの画像がウィンドウに表示されて
wiiリモコンを、ブンってやると、アプリケーションが終了して
その時点での画像が保存される。

もう少しちゃんと作ってみた。
http://code.google.com/p/aileron-hobby/