Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/brad-colbert/yail into main
Browse files Browse the repository at this point in the history
  • Loading branch information
colbertb committed Mar 29, 2024
2 parents 6693c31 + 044ec69 commit 45e94c9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
5 changes: 5 additions & 0 deletions server/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
requests>=1.0.0
duckduckgo_search>=1.0.0
fastcore>=1.0.0
pillow>=9.0.0
tqdm>=1.0.0
olefile>=0.0.0
numpy>=1.0.0
fastcore>=1.0.0
numpy>=1.24.4
tqdm>=4.66.2
Expand Down
37 changes: 27 additions & 10 deletions server/yeet_to_yail.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import sys

# Set up logging first thing
logging.basicConfig(level=logging.ERROR)
logging.basicConfig(level=logging.WARN)
logger = logging.getLogger(__name__)

GRAPHICS_8 = 2
Expand All @@ -38,6 +38,7 @@
camera_thread = None
camera_done = False
filenames = []
camera_name = None

def fix_aspect(image, crop=False):
aspect = YAIL_W/YAIL_H # YAIL aspect ratio
Expand Down Expand Up @@ -226,13 +227,23 @@ def camera_handler():

pygame.camera.init()

cameras = pygame.camera.list_cameras()
if camera_name is not None:
webcam = pygame.camera.Camera(camera_name)

logger.info("Using camera %s ..." % cameras[0])
webcam.start()
else:
cameras = pygame.camera.list_cameras()

# going to try each camera in the list until we have one
for camera in cameras:
try:
logger.info("Trying camera %s ..." % camera)

webcam = pygame.camera.Camera(cameras[0])
webcam = pygame.camera.Camera(camera) #'/dev/video60') #cameras[0])

webcam.start()
webcam.start()
except Exception as ex:
logger.warn("Unable to use camera %s ..." % camera)

# grab first frame
img = webcam.get_image()
Expand Down Expand Up @@ -415,6 +426,8 @@ def F(file_path):
filenames.append(file_path)

def main():
global camera_name

# Initialize the image to send with something
initial_image = Image.new("L", (YAIL_W,YAIL_H))
update_yail_data(pack_shades(initial_image))
Expand All @@ -431,23 +444,27 @@ def main():
# Check if any arguments were provided (other than the script name)
if len(sys.argv) > 1:
parser = argparse.ArgumentParser(description="Yeets images to YAIL")
parser.add_argument('paths', nargs='+', default=None, help='Directory path or list of file paths')
parser.add_argument('--extensions', nargs='+', default=['.jpg', '.jpeg', '.gif', '.png'], help='List of file extensions to process')
parser.add_argument('--mode', nargs='+', default='9', help='List of file extensions to process')
parser.add_argument('paths', nargs='?', default=None, help='Directory path or list of file paths')
parser.add_argument('--extensions', nargs='+', default=['.jpg', '.jpeg', '.gif', '.png'], help='List of file extensions to process', required=False)
parser.add_argument('--mode', nargs='?', default='9', help='List of file extensions to process', required=False)
parser.add_argument('--camera', nargs='?', default=None, help='The camera device to use', required=False)

args = parser.parse_args()

if args.mode == '8':
gfx_mode = GRAPHICS_8
elif args.mode == '9':
gfx_mode = GRAPHICS_9

if args.camera:
camera_name = args.camera

if len(args.paths) == 1 and os.path.isdir(args.paths[0]):
if args.paths is not None and len(args.paths) == 1 and os.path.isdir(args.paths[0]):
# If a single argument is passed and it's a directory
directory_path = args.paths[0]
print("Processing files in directory:")
process_files(directory_path, args.extensions, F)
else:
elif args.paths:
# If multiple file paths are passed
file_list = args.paths
print("\nProcessing specific files in list:")
Expand Down

0 comments on commit 45e94c9

Please sign in to comment.