есть такой код: он считывает с камеры данные и пишёт их на диск в видео-файл вопрос такой - как организовать процесс получения от камеры последовательности изображений(кадров) в какой-нибудь класс для дальнейшей их обработки? (системой искуственного зрения) я честно не понимаю что происходит после инициализации камеры - и вот интересует: что из этого нужно колупать и как? | Код | static void run(int i){
// get a list of all media devices, search default devices and formats, and print it out if args[x] = "-dd" // --------------------------------------------------------------------------------------------------------
Stdout.log("get list of all media devices ..."); java.util.Vector deviceListVector = CaptureDeviceManager.getDeviceList(null); if (deviceListVector == null) { Stdout.log("... error: media device list vector is null, program aborted"); System.exit(0); } if (deviceListVector.size() == 0) { Stdout.log("... error: media device list vector size is 0, program aborted"); System.exit(0); }
for (int x = 0; x < deviceListVector.size(); x++) { // display device name CaptureDeviceInfo deviceInfo = (CaptureDeviceInfo) deviceListVector.elementAt(x); String deviceInfoText = deviceInfo.getName(); if (debugDeviceList) Stdout.log("device " + x + ": " + deviceInfoText);
// display device formats Format deviceFormat[] = deviceInfo.getFormats(); for (int y = 0; y < deviceFormat.length; y++) { // serach for default video device if (captureVideoDevice == null) if (deviceFormat[y] instanceof VideoFormat) if (deviceInfo.getName().indexOf(defaultVideoDeviceName) >= 0) { captureVideoDevice = deviceInfo; Stdout.log(">>> capture video device = " + deviceInfo.getName()); }
// search for default video format if (captureVideoDevice == deviceInfo) if (captureVideoFormat == null) if (DeviceInfo.formatToString(deviceFormat[y]).indexOf(defaultVideoFormatString) >= 0) { captureVideoFormat = (VideoFormat) deviceFormat[y]; Stdout.log(">>> capture video format = " + DeviceInfo.formatToString(deviceFormat[y])); }
// serach for default audio device if (captureAudioDevice == null) if (deviceFormat[y] instanceof AudioFormat) if (deviceInfo.getName().indexOf(defaultAudioDeviceName) >= 0) { captureAudioDevice = deviceInfo; Stdout.log(">>> capture audio device = " + deviceInfo.getName()); }
// search for default audio format if (captureAudioDevice == deviceInfo) if (captureAudioFormat == null) if (DeviceInfo.formatToString(deviceFormat[y]).indexOf(defaultAudioFormatString) >= 0) { captureAudioFormat = (AudioFormat) deviceFormat[y]; Stdout.log(">>> capture audio format = " + DeviceInfo.formatToString(deviceFormat[y])); }
if (debugDeviceList) Stdout.log(" - format: " + DeviceInfo.formatToString(deviceFormat[y])); } } Stdout.log("... list completed.");
// if args[x] = "-dd" terminate now // -------------------------------- if (debugDeviceList) System.exit(0);
// setup video data source // ----------------------- MediaLocator videoMediaLocator = captureVideoDevice.getLocator(); DataSource videoDataSource = null; try { videoDataSource = javax.media.Manager.createDataSource(videoMediaLocator); } catch (IOException ie) { Stdout.logAndAbortException(ie); } catch (NoDataSourceException nse) { Stdout.logAndAbortException(nse); }
if (! DeviceInfo.setFormat(videoDataSource, captureVideoFormat)) { Stdout.log("Error: unable to set video format - program aborted"); System.exit(0); }
// setup audio data source // ----------------------- MediaLocator audioMediaLocator = captureAudioDevice.getLocator(); DataSource audioDataSource = null; try { audioDataSource = javax.media.Manager.createDataSource(audioMediaLocator); } catch (IOException ie) { Stdout.logAndAbortException(ie); } catch (NoDataSourceException nse) { Stdout.logAndAbortException(nse); }
if (! DeviceInfo.setFormat(audioDataSource, captureAudioFormat)) { Stdout.log("Error: unable to set audio format - program aborted"); System.exit(0); }
// merge the two data sources // -------------------------- DataSource mixedDataSource = null; try { DataSource dArray[] = new DataSource[2]; dArray[0] = videoDataSource; dArray[1] = audioDataSource; mixedDataSource = javax.media.Manager.createMergingDataSource(dArray); } catch (IncompatibleSourceException ise) { Stdout.logAndAbortException(ise); }
// create a new processor // ----------------------
// setup output file format ->> msvideo FileTypeDescriptor outputType = new FileTypeDescriptor(FileTypeDescriptor.MSVIDEO);
// setup output video and audio data format Format outputFormat[] = new Format[2]; outputFormat[0] = new VideoFormat(VideoFormat.INDEO50); outputFormat[1] = new AudioFormat(AudioFormat.LINEAR /* LINEAR */);
// create processor ProcessorModel processorModel = new ProcessorModel(mixedDataSource, outputFormat, outputType); Processor processor = null; try { processor = Manager.createRealizedProcessor(processorModel); } catch (IOException e) { Stdout.logAndAbortException(e); } catch (NoProcessorException e) { Stdout.logAndAbortException(e); } catch (CannotRealizeException e) { Stdout.logAndAbortException(e); }
// get the output of the processor DataSource source = processor.getDataOutput();
// create a File protocol MediaLocator with the location // of the file to which bits are to be written int k=i+10000; MediaLocator dest = new MediaLocator("file://K:/1/vid"+k+".avi");
// create a datasink to do the file DataSink dataSink = null; MyDataSinkListener dataSinkListener = null; try { dataSink = Manager.createDataSink(source, dest); dataSinkListener = new MyDataSinkListener(); dataSink.addDataSinkListener(dataSinkListener); dataSink.open(); } catch (IOException e) { Stdout.logAndAbortException(e); } catch (NoDataSinkException e) { Stdout.logAndAbortException(e); } catch (SecurityException e) { Stdout.logAndAbortException(e); }
// now start the datasink and processor try { dataSink.start(); } catch (IOException e) { Stdout.logAndAbortException(e); } processor.start();
Stdout.log("starting capturing ..."); try { Thread.currentThread().sleep(5*60000); } catch (InterruptedException ie) {} // capture for 10 seconds Stdout.log("... capturing done");
// stop and close the processor when done capturing... // close the datasink when EndOfStream event is received... processor.stop(); processor.close();
dataSinkListener.waitEndOfStream(10); dataSink.close();
Stdout.log("[all done]");
} |
--------------------
Если собака свернулась калачиком, значит будет дождь, а если сидит выпучив глаза, значит у неё запор.
|