def _init_camera(self, orig=True): """ Opens the video capture :return: True if the camera opens, or it isn't being used False if attempting to open the camera fails """ if orig: log.info('Using OpenCV version {}.{}'.format( cv2.getVersionMajor(), cv2.getVersionMinor())) if self.camera_id is not None: log.info('Using camera {}'.format(self.camera_id)) self.camera_instance = cv2.VideoCapture(self.camera_id) x, y, fps = self.resolution self.camera_instance.set(cv2.CAP_PROP_FRAME_WIDTH, x) self.camera_instance.set(cv2.CAP_PROP_FRAME_HEIGHT, y) self.camera_instance.set(cv2.CAP_PROP_FPS, fps) if not self.camera_instance.isOpened(): log.error('Failed to open camera') return False self.is_open = True x = self.camera_instance.get(cv2.CAP_PROP_FRAME_WIDTH) y = self.camera_instance.get(cv2.CAP_PROP_FRAME_HEIGHT) fps = self.camera_instance.get(cv2.CAP_PROP_FPS) log.warning('x: {}, y: {}, fps: {}'.format(x, y, fps)) return True
def version(): return "Pandas Version: {}" \ "Numpy Version: {}" \ "Opencv Version: {}" \ "Keras Version: {}" \ "Matplotlib Version: {}" \ "Scipy Version: {}" \ "Seaborn Version: {}" \ "Sklearn Version: {}" \ "Tensorflow Version: {}".format(pandas.__version__, numpy.__version__, cv2.getVersionMinor(), keras.__version__, matplotlib.__version__, scipy.__version__, seaborn.__version__, sklearn.__version__, tensorflow.__version__)
def check_build_info(): success = True print("OpenCV Version: {}".format(cv2.__version__)) if (cv2.getVersionMajor() != CURRENT_OPENCV_BUILD_VERSION[0]) and ( cv2.getVersionMinor() != CURRENT_OPENCV_BUILD_VERSION[1]) and ( cv2.getVersionRevision() != CURRENT_OPENCV_BUILD_VERSION[2]): print("ERROR: OpenCV version is different than the expected.") success = False print("Available CPUs: ", cv2.getNumberOfCPUs()) print("Available threads: ", cv2.getNumThreads()) if cv2.getNumThreads() < cv2.getNumberOfCPUs(): print("ERROR: TBB is not enabled.") success = False cv2.CPU_NEON = 100 # Value taken from OpenCV doc. CPU labels don't work correctly in Python print("Cpu NEON support: ", cv2.checkHardwareSupport(cv2.CPU_NEON)) if not cv2.checkHardwareSupport(cv2.CPU_NEON): print("ERROR: NEON is not enabled.") success = False return success
import cv2 import sys if __name__ == '__main__': # Set up tracker. # Instead of MIL, you can also use tracker_types = ['BOOSTING', 'MIL', 'KCF', 'TLD', 'MEDIANFLOW', 'GOTURN', 'MOSSE', 'CSRT'] tracker_type = tracker_types[2] if int(cv2.getVersionMinor()) < 3: tracker = cv2.Tracker_create(tracker_type) else: if tracker_type == 'BOOSTING': tracker = cv2.TrackerBoosting_create() if tracker_type == 'MIL': tracker = cv2.TrackerMIL_create() if tracker_type == 'KCF': tracker = cv2.TrackerKCF_create() if tracker_type == 'TLD': tracker = cv2.TrackerTLD_create() if tracker_type == 'MEDIANFLOW': tracker = cv2.TrackerMedianFlow_create() if tracker_type == 'GOTURN': tracker = cv2.TrackerGOTURN_create() if tracker_type == 'MOSSE': tracker = cv2.TrackerMOSSE_create() if tracker_type == "CSRT": tracker = cv2.TrackerCSRT_create() # Read video video = cv2.VideoCapture("videos/chaplin.mp4") # Exit if video not opened.