How to use the vidgear.gears.helper.check_CV_version function in vidgear

To help you get started, we’ve selected a few vidgear examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github abhiTronix / vidgear / vidgear / gears / stabilizer.py View on Github external
def generate_transformations(self):
		"""
		Generate pevious_2_current transformations [dx,dy,da]
		"""
		frame_gray = cv2.cvtColor(self.frame_queue[-1], cv2.COLOR_BGR2GRAY) #retrieve current frame and convert to gray
		frame_gray = self.clahe.apply(frame_gray) #optimize it

		#calculate optical flow using Lucas-Kanade differential method
		curr_kps, status, error = cv2.calcOpticalFlowPyrLK(self.previous_gray, frame_gray, self.previous_keypoints, None)
		
		#select only valid keypoints
		valid_curr_kps = curr_kps[status==1] #current
		valid_previous_keypoints = self.previous_keypoints[status==1] #previous
		
		#calculate optimal affine transformation between pevious_2_current keypoints
		if check_CV_version() == 3:
			#backward compatibility with OpenCV3 
			transformation = cv2.estimateRigidTransform(valid_previous_keypoints,valid_curr_kps, False)
		else:
			transformation = cv2.estimateAffinePartial2D(valid_previous_keypoints,valid_curr_kps)[0]
		
		#check if transformation is not None
		if not(transformation is None):
			# pevious_2_current translation in x direction
			dx = transformation[0, 2]
			# pevious_2_current translation in y direction
			dy = transformation[1, 2]
			# pevious_2_current rotation in angle
			da = np.arctan2(transformation[1, 0], transformation[0, 0])
		else:
			#otherwise zero it
			dx = dy = da = 0
github abhiTronix / vidgear / vidgear / gears / camgear.py View on Github external
from collections import deque
			#define deque and assign it to global var
			self.queue = deque(maxlen=96) #max len 96 to check overflow
			#log it
			if logging:
				print('Enabling Threaded Queue Mode for the current video source!') 
		else:
			#otherwise disable it
			self.threaded_queue_mode = False

		# stream variable initialization
		self.stream = None

		if backend and isinstance(backend, int):
			# add backend if specified and initialize the camera stream
			if check_CV_version() == 3:
				# Different OpenCV 3.4.x statement
				self.stream = cv2.VideoCapture(source + backend)
			else:
				# Two parameters are available since OpenCV 4+ (master branch)
				self.stream = cv2.VideoCapture(source, backend)
		else:
			# initialize the camera stream
			self.stream = cv2.VideoCapture(source)


		#initializing colorspace variable
		self.color_space = None

		try: 
			# try to apply attributes to source if specified
			#reformat dict