piloter_un_apn_lumix_depuis_son_ordinateur
Table des matières
Piloter un APN Lumix avec son ordinateur
Sélectionner le réseau Wi-Fi adéquat :
MENU -> [Config.] -> Wi-Fi -> Fonction Wi-Fi -> Nouvelle connexion -> Prise de vue et affichage à distance -> DISP. Changer de mode -> Par réseau -> Dans la liste
Processing
// http://www.personal-view.com/talks/discussion/6703/control-your-gh3-from-a-web-browser-now-with-video-/p1 import controlP5.*; import java.awt.image.*; import javax.imageio.*; import java.net.*; import java.io.*; ControlP5 cp5; ReceiverThread thread; XML xml; String adresse; int port; PImage video; void setup() { size(1000, 600); noStroke(); video = createImage(640, 480, RGB); thread = new ReceiverThread(video.width, video.height); thread.start(); cp5 = new ControlP5(this); cp5.addToggle("Mode") .setPosition(40, 250) .setSize(50, 20) .setValue(false) .setMode(ControlP5.SWITCH) ; cp5.addToggle("Diffusion") .setPosition(120, 250) .setSize(50, 20) .setValue(false) .setMode(ControlP5.SWITCH) ; cp5.addButton("Photo") .setValue(0) .setPosition(100, 300) .setSize(120, 120) ; cp5.addButton("Connexion") .setValue(0) .setPosition(100, 100) .setSize(80, 80) ; adresse = ""; port = 49152; } void draw() { background(0); if (thread.available()) { video = thread.getImage(); } image(video,300, 60); } void Connexion(int valeur) { println(valeur); adresse = "http://192.168.54.1/cam.cgi?mode="; xml = loadXML(adresse + "getstate"); // Connexion println("Connexion"); println(xml); } void Mode(boolean drapeau) { if (!drapeau && !adresse.equals("")) { xml = loadXML(adresse + "camcmd&value=recmode"); // Mode camera println("0"); } else { xml = loadXML(adresse + "camcmd&value=playmode"); // Mode lecture println("1"); } } void Diffusion(boolean drapeau) { println(adresse); if (!drapeau && !adresse.equals("")) { xml = loadXML(adresse + "startstream&value=" + port); // Diffusion println("0"); } else { xml = loadXML(adresse + "stopstream"); // Arret Diffusion println("1"); } } void keyPressed() { println(byte(key)); if (byte(key) == 10) { Photo(0); } } void Photo(int valeur) { xml = loadXML(adresse + "camcmd&value=capture"); // Diffusion println(xml); } // Daniel Shiffman // <http://www.shiffman.net> class ReceiverThread extends Thread { // Port we are receiving. int port = 49152; DatagramSocket ds; // A byte array to read into (max size of 65536, could be smaller) byte[] buffer = new byte[40000]; boolean running; // Is the thread running? Yes or no? boolean available; // Are there new tweets available? // Start with something PImage img; ReceiverThread (int w, int h) { img = createImage(w, h, RGB); running = false; available = true; // We start with "loading . . " being available try { ds = new DatagramSocket(port); } catch (SocketException e) { e.printStackTrace(); } } PImage getImage() { // We set available equal to false now that we've gotten the data available = false; return img; } boolean available() { return available; } // Overriding "start()" void start () { running = true; super.start(); } // We must implement run, this gets triggered by start() void run () { while (running) { checkForImage(); // New data is available! available = true; } } void checkForImage() { DatagramPacket p = new DatagramPacket(buffer, buffer.length); try { ds.receive(p); } catch (IOException e) { e.printStackTrace(); } byte[] data = p.getData(); int debutTrame = 0; for (int i = 0; i < 200; i++) { if ((int(data[i]) == 0xff) && (int(data[i + 1]) == 0xD8)) { debutTrame = i; } } // println("Received datagram with " + data.length + " bytes." ); data = subset(data, debutTrame, 30000); // Read incoming data into a ByteArrayInputStream ByteArrayInputStream bais = new ByteArrayInputStream( data ); // We need to unpack JPG and put it in the PImage img img.loadPixels(); try { // Make a BufferedImage out of the incoming bytes BufferedImage bimg = ImageIO.read(bais); // Put the pixels into the PImage bimg.getRGB(0, 0, img.width, img.height, img.pixels, 0, img.width); } catch (Exception e) { e.printStackTrace(); } // Update the PImage pixels img.updatePixels(); } // Our method that quits the thread void quit() { System.out.println("Quitting."); running = false; // Setting running to false ends the loop in run() // In case the thread is waiting. . . interrupt(); } }
Sources
piloter_un_apn_lumix_depuis_son_ordinateur.txt · Dernière modification : 2023/09/01 00:16 de Mushussu