<commit_before>#!/usr/bin/env python
# encoding=utf-8

# you need to install opencv before running the script import cv2
import cv2
import time	# sleep
import sys	# exit

__author__ = "<NAME>"
__copyright__ = "Copyright (c) 2017, <NAME>"
__credits__ = ["<NAME>", "<NAME>"]
__license__ = "MIT"
__email__ = "<EMAIL>"

# initialize video capture from builtin webcam
cap = cv2.VideoCapture(0)

# OPTIONAL: define the desired image width (in pixel) here
image_width = 100

try: 
	while True:
		# read frame from web cam
		ret, frame = cap.read()

		# convert frame to grayscale image
		img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

		# get the height and width of the image
		height, width = img.shape

		# resize the image
		img = cv2.resize(img,(image_width, height*image_width/width), interpolation = cv2.INTER_CUBIC)

		# get the new height and width of the image
		height, width = img.shape

		# initialize an empty string to store the entire frame of text
		frameToPrint = ""

		# loop through each row of pixels of the image
		for i in range(height):

			# loop through each pixel in the i-th row of the image
			for j in range(width):

				# write corresponding chinese characters based on the color of the pixel
				if img[i,j] < 32:
					frameToPrint += "龘"
				elif img[i,j] < 64:
					frameToPrint += "驫"
				elif img[i,j] < 96:
					frameToPrint += "羴"
				elif img[i,j] < 128:
					frameToPrint += "淼"
				elif img[i,j] < 160:
					frameToPrint += "壵"
				elif img[i,j] < 192:
					frameToPrint += "从"
				elif img[i,j] < 224:
					frameToPrint += "人"
				else:
					frameToPrint += "一"

			# write a new line
			frameToPrint += "\n"
		# clear the terminal window
		print(chr(27) + "[2J")

		# print out the frame
		print frameToPrint

		# define the period of time each frame's gonna last
		time.sleep(0.2)

# handle KeyboardInterrupt, typically Ctrl + C
except KeyboardInterrupt:
	# release the video capture
	cap.release()
	sys.exit()<commit_msg>features ported to webcam.py<commit_after>#!/usr/bin/env python
# encoding=utf-8

# you need to install opencv before running the script import cv2
import cv2
import time	# sleep
import sys	# exit

__author__ = "<NAME>"
__copyright__ = "Copyright (c) 2017, <NAME>"
__credits__ = ["<NAME>", "<NAME>"]
__license__ = "MIT"
__email__ = "<EMAIL>"

# initialize video capture from builtin webcam
cap = cv2.VideoCapture(0)

# OPTIONAL: define the desired image width (in pixel) here
image_width = 64

# OPTIONAL: comment out the list you like or even define your own character list
char_list = ["龘","麤","驫","羴","掱","蟲","𣝯","淼","品","壵","尛","太","大","人","丿","丶"] # 16-bit char list
#char_list = ["龘","驫","羴","淼","壵","从","人","一"] # 8-bit char list
#char_list = ["龘","淼","从","人"] # 4-bit char list

# OPTIONAL: whehter or not to reverse the image
image_reverse = False

# OPTIONAL: whether or not to add a space between characters
add_space = False

try: 
	while True:
		# read frame from web cam
		ret, frame = cap.read()

		# convert frame to grayscale image
		img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

		# get the height and width of the image
		height, width = img.shape

		# resize the image
		img = cv2.resize(img,(image_width, height*image_width/width), interpolation = cv2.INTER_CUBIC)

		# get the new height and width of the image
		height, width = img.shape

		# initialize an empty string to store the entire frame of text
		frameToPrint = ""

		# loop through each row of pixels of the image
		for i in range(height):

			# loop through each pixel in the i-th row of the image
			for j in range(width):

				# write corresponding chinese characters based on the color of the pixel
                                char_length = len(char_list)
                                for k in range(char_length):
                                    if img[i, j] < 256/char_length*(k+1) and img[i, j] >= 256/char_length*k:
                                        if image_reverse:
                                            frameToPrint += char_list[char_length-k-1]
                                        else:
                                            frameToPrint += char_list[k]
                                        if add_space:
                                            frameToPrint += ' '
                                        break

			# write a new line
			frameToPrint += "\n"
		# clear the terminal window
		print(chr(27) + "[2J")

		# print out the frame
		print frameToPrint

		# define the period of time each frame's gonna last
		time.sleep(0.2)

# handle KeyboardInterrupt, typically Ctrl + C
except KeyboardInterrupt:
	# release the video capture
	cap.release()
	sys.exit()
{'fraction_non_alphanumeric': 0.10676691729323308, 'fraction_numerical': 0.015682062298603652, 'mean_word_length': 2.606506584043377, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6901706', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1458, 'n_words': 512}