本文整理汇总了Java中org.opencv.videoio.VideoCapture类的典型用法代码示例。如果您正苦于以下问题:Java VideoCapture类的具体用法?Java VideoCapture怎么用?Java VideoCapture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VideoCapture类属于org.opencv.videoio包,在下文中一共展示了VideoCapture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Webcam
import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
Webcam() {
cap = new VideoCapture(0);
if (!cap.isOpened()) {
System.out.println("Camera Error");
} else {
System.out.println("Camera OK?");
cap.set(Videoio.CV_CAP_PROP_FRAME_WIDTH, width);
cap.set(Videoio.CV_CAP_PROP_FRAME_HEIGHT, height);
}
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
}
cap.read(mat);
System.out.println("width, height = "+mat.cols()+", "+mat.rows());
}
示例2: startDetecting
import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public void startDetecting() {
capture = new VideoCapture();
capture.open(0);
Runnable frameGrabber = new Runnable() {
@Override
public void run() {
// effectively grab and process a single frame
grabFrame();
// convert and show the frame
//TODO trigger listener up here
}
};
this.timer = Executors.newSingleThreadScheduledExecutor();
this.timer.scheduleAtFixedRate(frameGrabber, 0, 20, TimeUnit.MILLISECONDS);
}
示例3: MainFrame
import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public MainFrame()
{
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
setPreferredSize(new Dimension(640, 480));
cap = new VideoCapture(0);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
cap.release();
System.exit(0);
}
});
p = new DrawPanel();
add(p);
setVisible(true);
}
示例4: init
import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
@Override
protected void init(final ProcessorInitializationContext context) {
final List<PropertyDescriptor> descriptors = new ArrayList<PropertyDescriptor>();
// descriptors.add(CAMERA);
descriptors.add(FRAME_WIDTH);
descriptors.add(FRAME_HEIGHT);
this.descriptors = Collections.unmodifiableList(descriptors);
final Set<Relationship> relationships = new HashSet<Relationship>();
relationships.add(REL_SUCCESS);
this.relationships = Collections.unmodifiableSet(relationships);
OpenCV.loadShared();
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
camera = new VideoCapture();
camera.open(0);
}
示例5: patternCapture
import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public void patternCapture(VideoCapture capture, EyeDetection e, int length, String cmd){
//Scanner scanner = new Scanner(System.in);
List<EyeStatus> eyeStatusList = new ArrayList<>();
Calculation calculation = new Calculation(this);
Mat frame = new Mat();
List<Circle> circleList = new ArrayList<>();
//System.out.println("How big will your pattern be?");
//length = scanner.nextInt(); //excpetion
for(int i = 0; i < length; i++) {
//System.out.println("Do step " + (i + 1));
pressAnyKeyToContinue("Do step " + (i + 1));
if(capture.read(frame)) {
circleList = e.eyeDetect(frame);
e.filter(circleList);
//Calculate
eyeStatusList.add(calculation.calculate(frame, circleList));
}
}
for(EyeStatus eye : eyeStatusList) {
System.out.println(eye.getLeft() + " " + eye.getRight());
}
PatternDatabase.writeNewPattern(eyeStatusList, cmd);
capture.release();
}
示例6: ImageProcessor
import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public ImageProcessor(int webcam, VisionNetworkTable visionTable) {
capture = new VideoCapture(webcam);
capture.set(Videoio.CAP_PROP_FRAME_WIDTH, 640); // width
capture.set(Videoio.CAP_PROP_FRAME_HEIGHT, 480); // height
this.visionTable = visionTable;
this.scheduler = Executors.newScheduledThreadPool(1);
originalImage = new Mat();
hslImage = new Mat();
maskImage = new Mat();
hierarchy = new Mat();
setCameraManualExposure();
setCameraAbsoluteExposure();
setCameraBrightness();
System.out.println("ImageProcesser constructor done");
}
示例7: CamFaceDetector
import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public static void CamFaceDetector() {
try {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
final CascadeClassifier objDetector = new CascadeClassifier(CameraFacialRecognition.class
.getResource("../../../../../opencv/sources/data/lbpcascades/lbpcascade_frontalface_improved.xml")
.getPath().substring(1));
final Mat capImg = new Mat();
final VideoCapture capture = new VideoCapture(0);
final int height = (int) capture.get(Videoio.CV_CAP_PROP_FRAME_HEIGHT);
final int width = (int) capture.get(Videoio.CV_CAP_PROP_FRAME_WIDTH);
if (height == 0 || width == 0) {
throw new Exception("camera not found");
}
final JFrame frame = new JFrame("camera");
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
final CameraFacialRecognition panel = new CameraFacialRecognition();
frame.setContentPane(panel);
frame.setVisible(true);
frame.setSize(width + frame.getInsets().left + frame.getInsets().right,
height + frame.getInsets().top + frame.getInsets().bottom);
Mat dst = new Mat();
while (frame.isShowing()) {
capture.read(capImg);
dst = dobj(objDetector, capImg);
panel.mImg = Mat2BufferedImage.mat2BI(dst);
panel.repaint();
}
capture.release();
} catch (final Exception e) {
System.out.println("Exception" + e);
} finally {
System.out.println("--done--");
}
}
示例8: USBCamera
import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
/**
* Constructs a new <code>USBCamera</code>
* @param number the port number for the camera
* @param fov the field of view of the camera in degrees
*/
public USBCamera(int number, double fov) {
super(fov);
this.number = number;
vc = new VideoCapture();
vc.open(this.number);
}
示例9: init
import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public void init() {
System.out.println("INIT");
cap = new VideoCapture();
faceCascade = new CascadeClassifier();
imageView.setFitWidth(640);
imageView.setPreserveRatio(true);
faceCascade.load("res/haarcascade_frontalface_alt.xml");
}
示例10: init
import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public void init() { // external
System.out.println("[Controller] Initializing controller");
cap = new VideoCapture();
// fix imageViews so they don't resize
imageView.setFitWidth(640);
imageView.setPreserveRatio(true);
imageViewAlpha.setFitWidth(320);
imageViewAlpha.setPreserveRatio(true);
imageViewBeta.setFitWidth(320);
imageViewBeta.setPreserveRatio(true);
}
示例11: grabImage
import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public void grabImage(){
Mat frame = new Mat();
//connect
videoCapture = new VideoCapture(0);
isOpened = videoCapture.isOpened();
System.out.println("connected: " + isOpened);
//setSetting
videoCapture.set(Videoio.CV_CAP_PROP_FRAME_WIDTH, 1280);
videoCapture.set(Videoio.CV_CAP_PROP_FRAME_HEIGHT, 720);
//startGrab
isSucceed = videoCapture.grab();
System.out.println("started: " + String.valueOf(isSucceed));
if ((!isOpened) || (!isSucceed))
return;
System.out.println("------- START GRAB -------");
//Wait for camera starting
while (true){
videoCapture.read(frame);
if (!frame.empty())
break;
}
int frameNo = 0;
long startSysMillis = System.currentTimeMillis();
while (frameNo < 1000){
videoCapture.read(frame);
frameNo++;
}
System.out.println(frameNo + " frames in " + (System.currentTimeMillis() - startSysMillis) + " millis");
videoCapture.release(); // release device
System.out.println('\n' + "Done");
}
示例12: MainFrame
import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public MainFrame()
{
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
setPreferredSize(new Dimension(640, 480));
cap = new VideoCapture(0);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
cap.release();
System.exit(0);
}
});
p = new DrawPanel();
add(p);
pack();
setVisible(true);
}
示例13: main
import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public static void main(String[] args)
{
System.out.println("Hello, OpenCV");
// Load the native library.
System.loadLibrary("opencv_java244");
VideoCapture camera = new VideoCapture(0);
camera.open(0); //Useless
if(!camera.isOpened()){
System.out.println("Camera Error");
}
else{
System.out.println("Camera OK?");
}
Mat frame = new Mat();
//camera.grab();
//System.out.println("Frame Grabbed");
//camera.retrieve(frame);
//System.out.println("Frame Decoded");
camera.read(frame);
System.out.println("Frame Obtained");
/* No difference
camera.release();
*/
System.out.println("Captured Frame Width " + frame.width());
Imgcodecs.imwrite("camera.jpg", frame);
System.out.println("OK");
}
示例14: CvMultiCamera
import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
/**
* Opens a new camera using openCV with a given frame width and height,
* and a compression quality.
* <p>
* Checks all available devices up to index 10 and adds them using
* {@link CameraView#add(Camera)}.
* </p>
*
* @param name the name of the camera
* @param current the device index from 0.
* @param width the frame width
* @param height the frame height
* @param quality the compression quality
*
* @throws RuntimeException if the camera could not be opened
*/
public CvMultiCamera(String name, int current, int width, int height, int quality) {
super(name, null);
capture = new VideoCapture();
cams = checkCameras(capture, 10);
if(current >= 0){
capture.open(current);
camIndex = current;
}
image = new Mat();
buffer = new MatOfByte();
compressParams = new MatOfInt(Imgcodecs.CV_IMWRITE_JPEG_QUALITY, quality);
capture.set(Videoio.CAP_PROP_FRAME_WIDTH, width);
capture.set(Videoio.CAP_PROP_FRAME_HEIGHT, height);
this.height = height;
this.width = width;
this.quality = quality;
Camera nullcam = null;
for (int i = 0; i < cams.length; i++) {
if(cams[i] >= 0){
add(nullcam);
}
}
}
示例15: checkCameras
import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
private static int[] checkCameras(VideoCapture cap, int max){
int[] cams = new int[max];
boolean end = false;
for (int i = 0; i < max; i++) {
if(!end){
if(!cap.open(i)){
cams[i] = -1;
end = true;
}else cams[i] = i;
cap.release();
}else cams[i] = -1;
}
return cams;
}