@Test public void testVideoInvalidLocation() { try { Map<String, String> config = new LinkedHashMap<>(); config.put("fileLocation", "invalidLocation"); config.put("fileExtension", "mov"); fr.setupDataRetrieval(config, source); fail("Expected setup exception on invalid video"); } catch (Exception e) { assertTrue("Failure should be caused by nonexistent video. Error actually was: " + e.getMessage() , e.getMessage().startsWith(FileRetriever.class.getCanonicalName() + ".mainVideoDoesNotExist")); } }
@Override public void setupDataRetrieval(Map<String, ?> dataSourceConfig, ObjectRecognitionCore source) throws Exception { if (dataSourceConfig.get(FILE_EXTENSION) instanceof String) { String ext = (String) dataSourceConfig.get(FILE_EXTENSION); if (ext.equals("mov") || ext.equals("mp4")) { isMov = true; } } try { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } catch (Throwable t) { throw new Exception(this.getClass().getCanonicalName() + ".opencvDependency" + ": Could not load OpenCv for FileRetriever." + "This is most likely due to a missing .dll/.so/.dylib. Please ensure that the environment " + "variable 'OPENCV_LOC' is set to the directory containing '" + Core.NATIVE_LIBRARY_NAME + "' and any other library requested by the attached error", t); } if (dataSourceConfig.get(FILE_LOCATION) instanceof String) { defaultImageLocation = (String) dataSourceConfig.get(FILE_LOCATION); if (isMov) { capture = new VideoCapture(defaultImageLocation); if (!capture.isOpened()) { capture.release(); if (!new File(defaultImageLocation).exists()) { throw new ImageAcquisitionException(this.getClass().getCanonicalName() + ".mainVideoDoesNotExist: " + "The requested video '" + defaultImageLocation + "' does not exist"); } throw new IllegalArgumentException(this.getClass().getCanonicalName() + ".invalidMainVideo: " + "Intended video '" + defaultImageLocation + "' could not be opened. Most likely OpenCV is not " + "compiled with the codecs required to read this video type"); } double videoFps = capture.get(Videoio.CAP_PROP_FPS); if (videoFps == 0) { videoFps = 24; } double fps = 0; if (dataSourceConfig.get(FPS) instanceof Number) { fps = ((Number) dataSourceConfig.get(FPS)).doubleValue(); } if (fps <= 0) { frameInterval = 1; } else { frameInterval = (int) Math.ceil(videoFps / fps); } } } }
FileRetriever implements ImageRetrieverInterface { @Override public void setupDataRetrieval(Map<String, ?> dataSourceConfig, ObjectRecognitionCore source) throws Exception { if (dataSourceConfig.get(FILE_EXTENSION) instanceof String) { String ext = (String) dataSourceConfig.get(FILE_EXTENSION); if (ext.equals("mov") || ext.equals("mp4")) { isMov = true; } } try { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } catch (Throwable t) { throw new Exception(this.getClass().getCanonicalName() + ".opencvDependency" + ": Could not load OpenCv for FileRetriever." + "This is most likely due to a missing .dll/.so/.dylib. Please ensure that the environment " + "variable 'OPENCV_LOC' is set to the directory containing '" + Core.NATIVE_LIBRARY_NAME + "' and any other library requested by the attached error", t); } if (dataSourceConfig.get(FILE_LOCATION) instanceof String) { defaultImageLocation = (String) dataSourceConfig.get(FILE_LOCATION); if (isMov) { capture = new VideoCapture(defaultImageLocation); if (!capture.isOpened()) { capture.release(); if (!new File(defaultImageLocation).exists()) { throw new ImageAcquisitionException(this.getClass().getCanonicalName() + ".mainVideoDoesNotExist: " + "The requested video '" + defaultImageLocation + "' does not exist"); } throw new IllegalArgumentException(this.getClass().getCanonicalName() + ".invalidMainVideo: " + "Intended video '" + defaultImageLocation + "' could not be opened. Most likely OpenCV is not " + "compiled with the codecs required to read this video type"); } double videoFps = capture.get(Videoio.CAP_PROP_FPS); if (videoFps == 0) { videoFps = 24; } double fps = 0; if (dataSourceConfig.get(FPS) instanceof Number) { fps = ((Number) dataSourceConfig.get(FPS)).doubleValue(); } if (fps <= 0) { frameInterval = 1; } else { frameInterval = (int) Math.ceil(videoFps / fps); } } } } }
FileRetriever implements ImageRetrieverInterface { @Override public void setupDataRetrieval(Map<String, ?> dataSourceConfig, ObjectRecognitionCore source) throws Exception { if (dataSourceConfig.get(FILE_EXTENSION) instanceof String) { String ext = (String) dataSourceConfig.get(FILE_EXTENSION); if (ext.equals("mov") || ext.equals("mp4")) { isMov = true; } } try { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } catch (Throwable t) { throw new Exception(this.getClass().getCanonicalName() + ".opencvDependency" + ": Could not load OpenCv for FileRetriever." + "This is most likely due to a missing .dll/.so/.dylib. Please ensure that the environment " + "variable 'OPENCV_LOC' is set to the directory containing '" + Core.NATIVE_LIBRARY_NAME + "' and any other library requested by the attached error", t); } if (dataSourceConfig.get(FILE_LOCATION) instanceof String) { defaultImageLocation = (String) dataSourceConfig.get(FILE_LOCATION); if (isMov) { capture = new VideoCapture(defaultImageLocation); if (!capture.isOpened()) { capture.release(); if (!new File(defaultImageLocation).exists()) { throw new ImageAcquisitionException(this.getClass().getCanonicalName() + ".mainVideoDoesNotExist: " + "The requested video '" + defaultImageLocation + "' does not exist"); } throw new IllegalArgumentException(this.getClass().getCanonicalName() + ".invalidMainVideo: " + "Intended video '" + defaultImageLocation + "' could not be opened. Most likely OpenCV is not " + "compiled with the codecs required to read this video type"); } double videoFps = capture.get(Videoio.CAP_PROP_FPS); if (videoFps == 0) { videoFps = 24; } double fps = 0; if (dataSourceConfig.get(FPS) instanceof Number) { fps = ((Number) dataSourceConfig.get(FPS)).doubleValue(); } if (fps <= 0) { frameInterval = 1; } else { frameInterval = (int) Math.ceil(videoFps / fps); } } } }  }
FileRetriever implements ImageRetrieverInterface { @Override public void setupDataRetrieval(Map<String, ?> dataSourceConfig, ObjectRecognitionCore source) throws Exception { if (dataSourceConfig.get(FILE_EXTENSION) instanceof String) { String ext = (String) dataSourceConfig.get(FILE_EXTENSION); if (ext.equals("mov") || ext.equals("mp4")) { isMov = true; } } try { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } catch (Throwable t) { throw new Exception(this.getClass().getCanonicalName() + ".opencvDependency" + ": Could not load OpenCv for FileRetriever." + "This is most likely due to a missing .dll/.so/.dylib. Please ensure that the environment " + "variable 'OPENCV_LOC' is set to the directory containing '" + Core.NATIVE_LIBRARY_NAME + "' and any other library requested by the attached error", t); } if (dataSourceConfig.get(FILE_LOCATION) instanceof String) { defaultImageLocation = (String) dataSourceConfig.get(FILE_LOCATION); if (isMov) { capture = new VideoCapture(defaultImageLocation); if (!capture.isOpened()) { capture.release(); if (!new File(defaultImageLocation).exists()) { throw new ImageAcquisitionException(this.getClass().getCanonicalName() + ".mainVideoDoesNotExist: " + "The requested video '" + defaultImageLocation + "' does not exist"); } throw new IllegalArgumentException(this.getClass().getCanonicalName() + ".invalidMainVideo: " + "Intended video '" + defaultImageLocation + "' could not be opened. Most likely OpenCV is not " + "compiled with the codecs required to read this video type"); } double videoFps = capture.get(Videoio.CAP_PROP_FPS); if (videoFps == 0) { videoFps = 24; } double fps = 0; if (dataSourceConfig.get(FPS) instanceof Number) { fps = ((Number) dataSourceConfig.get(FPS)).doubleValue(); } if (fps <= 0) { frameInterval = 1; } else { frameInterval = (int) Math.ceil(videoFps / fps); } } } }  @Override void setupDataRetrieval(Map<String, ?> dataSourceConfig, ObjectRecognitionCore source); @Override ImageRetrieverResults getImage(); @Override ImageRetrieverResults getImage(Map<String, ?> request); @Override void close(); }
FileRetriever implements ImageRetrieverInterface { @Override public void setupDataRetrieval(Map<String, ?> dataSourceConfig, ObjectRecognitionCore source) throws Exception { if (dataSourceConfig.get(FILE_EXTENSION) instanceof String) { String ext = (String) dataSourceConfig.get(FILE_EXTENSION); if (ext.equals("mov") || ext.equals("mp4")) { isMov = true; } } try { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } catch (Throwable t) { throw new Exception(this.getClass().getCanonicalName() + ".opencvDependency" + ": Could not load OpenCv for FileRetriever." + "This is most likely due to a missing .dll/.so/.dylib. Please ensure that the environment " + "variable 'OPENCV_LOC' is set to the directory containing '" + Core.NATIVE_LIBRARY_NAME + "' and any other library requested by the attached error", t); } if (dataSourceConfig.get(FILE_LOCATION) instanceof String) { defaultImageLocation = (String) dataSourceConfig.get(FILE_LOCATION); if (isMov) { capture = new VideoCapture(defaultImageLocation); if (!capture.isOpened()) { capture.release(); if (!new File(defaultImageLocation).exists()) { throw new ImageAcquisitionException(this.getClass().getCanonicalName() + ".mainVideoDoesNotExist: " + "The requested video '" + defaultImageLocation + "' does not exist"); } throw new IllegalArgumentException(this.getClass().getCanonicalName() + ".invalidMainVideo: " + "Intended video '" + defaultImageLocation + "' could not be opened. Most likely OpenCV is not " + "compiled with the codecs required to read this video type"); } double videoFps = capture.get(Videoio.CAP_PROP_FPS); if (videoFps == 0) { videoFps = 24; } double fps = 0; if (dataSourceConfig.get(FPS) instanceof Number) { fps = ((Number) dataSourceConfig.get(FPS)).doubleValue(); } if (fps <= 0) { frameInterval = 1; } else { frameInterval = (int) Math.ceil(videoFps / fps); } } } }  @Override void setupDataRetrieval(Map<String, ?> dataSourceConfig, ObjectRecognitionCore source); @Override ImageRetrieverResults getImage(); @Override ImageRetrieverResults getImage(Map<String, ?> request); @Override void close();  }