<commit_before># -*- coding:utf-8 -*- 


#
# Module to display live images from two cameras
#


#
# External dependencies
#
import time
import cv2
import numpy as np
import Vimba


#
# Find the chessboard quickly, and draw it
#
def PreviewChessboard( image, pattern_size ) :
	
	# Find the chessboard corners on the image
	found, corners = cv2.findChessboardCorners( image, pattern_size, flags = cv2.CALIB_CB_FAST_CHECK )	
#	found, corners = cv2.findCirclesGridDefault( image, pattern_size, flags = cv2.CALIB_CB_ASYMMETRIC_GRID )	

	# Draw the chessboard corners on the image
	if found : cv2.drawChessboardCorners( image, pattern_size, corners, found )
		
	# Return the image with the chessboard if found
	return image


#
# Usb stereo camera viewer
#
def UsbStereoViewer( pattern_size ) :
		

	# Initialize the viewing parameters
	chessboard_enabled = False
	cross_enabled = False
	
	# Initialize the stereo cameras
	camera_left = cv2.VideoCapture( 0 )
	camera_right = cv2.VideoCapture( 1 )
	
	# Lower the camera frame rate
	camera_left.set( cv2.cv.CV_CAP_PROP_FPS, 5 )
	camera_right.set( cv2.cv.CV_CAP_PROP_FPS, 5 )

	# Live display
	while True :

		# Capture images
		camera_left.grab()
		camera_right.grab()

		# Get the images
		_, image_left = camera_left.retrieve()
		_, image_right = camera_right.retrieve()

		# Copy images for display
		image_left_displayed = np.array( image_left )
		image_right_displayed = np.array( image_right )

		# Preview the calibration chessboard on the image
		if chessboard_enabled :
			image_left_displayed = PreviewChessboard( image_left_displayed, pattern_size )
			image_right_displayed = PreviewChessboard( image_right_displayed, pattern_size )

		# Display a cross in the middle of the image
		if cross_enabled :
			w = image_left_displayed.shape[1]
			h = image_left_displayed.shape[0]
			w2 = int( w/2 )
			h2 = int( h/2 )
			cv2.line( image_left_displayed, (w2, 0), (w2, h), (0, 255, 0), 2 )
			cv2.line( image_left_displayed, (0, h2), (w, h2), (0, 255, 0), 2 )
			cv2.line( image_right_displayed, (w2, 0), (w2, h), (0, 255, 0), 2 )
			cv2.line( image_right_displayed, (0, h2), (w, h2), (0, 255, 0), 2 )

		# Prepare image for display
		stereo_image = np.concatenate( (image_left_displayed, image_right_displayed), axis=1 )
		
		# Display the image (scaled down)
		cv2.imshow( 'StereoVision', stereo_image )

		# Keyboard interruption
		key = cv2.waitKey( 1 ) & 0xFF
		
		# Escape key
		if key == 27 :
			
			# Exit live display
			break
			
		# Space key
		elif key == 32 :
			
			# Save images to disk 
			current_time = time.strftime( '%Y%m%d_%H%M%S' )
			print( 'Save images {} to disk...'.format(current_time) )
			if chessboard_enabled :
				cv2.imwrite( 'Calibration/left-{}.png'.format(current_time), image_left )
				cv2.imwrite( 'Calibration/right-{}.png'.format(current_time), image_right )
			else :
				cv2.imwrite( 'left.png', image_left )
				cv2.imwrite( 'right.png', image_right )
			
		# C key
		elif key == ord('c') :
			
			# Enable / Disable display of the middle cross
			cross_enabled = not cross_enabled		

		# M key
		elif key == ord('m') :
			
			# Enable / Disable chessboard preview<commit_msg>Create symbolic links to the last saved images.<commit_after># -*- coding:utf-8 -*- 


#
# Module to display live images from two cameras
#


#
# External dependencies
#
import os
import time
import cv2
import numpy as np
import Vimba


#
# Find the chessboard quickly, and draw it
#
def PreviewChessboard( image, pattern_size ) :
	
	# Find the chessboard corners on the image
	found, corners = cv2.findChessboardCorners( image, pattern_size, flags = cv2.CALIB_CB_FAST_CHECK )	
#	found, corners = cv2.findCirclesGridDefault( image, pattern_size, flags = cv2.CALIB_CB_ASYMMETRIC_GRID )	

	# Draw the chessboard corners on the image
	if found : cv2.drawChessboardCorners( image, pattern_size, corners, found )
		
	# Return the image with the chessboard if found
	return image


#
# Usb stereo camera viewer
#
def UsbStereoViewer( pattern_size ) :
		

	# Initialize the viewing parameters
	chessboard_enabled = False
	cross_enabled = False
	
	# Initialize the stereo cameras
	camera_left = cv2.VideoCapture( 0 )
	camera_right = cv2.VideoCapture( 1 )
	
	# Lower the camera frame rate
	camera_left.set( cv2.cv.CV_CAP_PROP_FPS, 5 )
	camera_right.set( cv2.cv.CV_CAP_PROP_FPS, 5 )

	# Live display
	while True :

		# Capture images
		camera_left.grab()
		camera_right.grab()

		# Get the images
		_, image_left = camera_left.retrieve()
		_, image_right = camera_right.retrieve()

		# Copy images for display
		image_left_displayed = np.array( image_left )
		image_right_displayed = np.array( image_right )

		# Preview the calibration chessboard on the image
		if chessboard_enabled :
			image_left_displayed = PreviewChessboard( image_left_displayed, pattern_size )
			image_right_displayed = PreviewChessboard( image_right_displayed, pattern_size )

		# Display a cross in the middle of the image
		if cross_enabled :
			w = image_left_displayed.shape[1]
			h = image_left_displayed.shape[0]
			w2 = int( w/2 )
			h2 = int( h/2 )
			cv2.line( image_left_displayed, (w2, 0), (w2, h), (0, 255, 0), 2 )
			cv2.line( image_left_displayed, (0, h2), (w, h2), (0, 255, 0), 2 )
			cv2.line( image_right_displayed, (w2, 0), (w2, h), (0, 255, 0), 2 )
			cv2.line( image_right_displayed, (0, h2), (w, h2), (0, 255, 0), 2 )

		# Prepare image for display
		stereo_image = np.concatenate( (image_left_displayed, image_right_displayed), axis=1 )
		
		# Display the image (scaled down)
		cv2.imshow( 'StereoVision', stereo_image )

		# Keyboard interruption
		key = cv2.waitKey( 1 ) & 0xFF
		
		# Escape key
		if key == 27 :
			
			# Exit live display
			break
			
		# Space key
		elif key == 32 :
			
			# Save images to disk 
			current_time = time.strftime( '%Y%m%d_%H%M%S' )
			print( 'Save images {} to disk...'.format(current_time) )
			if chessboard_enabled :
				cv2.imwrite( 'Calibration/left-{}.png'.format(current_time), image_left )
				cv2.imwrite( 'Calibration/right-{}.png'.format(current_time), image_right )
			else :
				cv2.imwrite( 'left-{}.png'.format(current_time), image_left )
				cv2.imwrite( 'right-{}.png'.format(current_time), image_right )
				os.link( 'left-{}.png'.format(current_time), 'left.png' )
				os.link( 'right-{}.png'.format(current_time), 'right.png' )
			
		# C key
		elif key == ord('c') :
			
			# Enable / Disable display of the middle cross
			cross_enabled = not cross_enabled		

		# M key
		elif key == ord('m') :
			
			# Enable / Disable chessboard preview
{'fraction_non_alphanumeric': 0.10909368324687214, 'fraction_numerical': 0.022581629539212694, 'mean_word_length': 3.652235628105039, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2206477', 'n_tokens_mistral': 2688, 'n_tokens_neox': 2306, 'n_words': 624}