【发布时间】:2016-06-23 14:42:12
【问题描述】:
我正在尝试使用我的无人机摄像头而不是我的网络摄像头。我在 Eclipse 的 java 中使用 YADrone API 和 OpenCV。
package Drone;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.videoio.VideoCapture;
import org.opencv.videoio.Videoio;
import de.yadrone.base.IARDrone;
public class Video{
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
private JFrame frame;
private JLabel imageLabel;
public static void main(String[] args) {
Video app = new Video();
app.initGUI();
IARDrone drone = null;
app.runMainLoop(args, drone);
}
private void initGUI() {
frame = new JFrame("Camera Input Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(700, 450);
imageLabel = new JLabel();
frame.add(imageLabel);
frame.setVisible(true);
}
private void runMainLoop(String[] args, final IARDrone drone) {
ImageProcessor imageProcessor = new ImageProcessor();
Mat camMatImage = new Mat();
Image tempImage;
VideoCapture capture = new VideoCapture(0);
capture.set(Videoio.CAP_PROP_FRAME_WIDTH, 800);
capture.set(Videoio.CAP_PROP_FRAME_HEIGHT, 800);
if (capture.isOpened()) {
while (true) {
capture.read(camMatImage);
if (!camMatImage.empty()) {
tempImage = imageProcessor.toBufferedImage(camMatImage);
ImageIcon imageIcon = new ImageIcon(tempImage, "Captured video");
imageLabel.setIcon(imageIcon);
frame.pack(); // this will resize the window to fit the
// image
} else {
System.out.println(" -- Frame not captured -- Break!");
break;
}
}
} else {
System.out.println("Couldn't open capture.");
}
}
}
当通过 wifi 连接到无人机 (Parrot AR 2.0) 时,它仍然瞄准我笔记本电脑上的网络摄像头。我应该如何瞄准无人机相机而不是笔记本电脑上的网络摄像头?任何帮助将不胜感激:)
【问题讨论】:
-
VideoCapture(0) 打开默认摄像头。尝试使用其他设备 ID,或使用正确的连接字符串