From 0df736d86e943491d12c3a316316a7da15dcd15f Mon Sep 17 00:00:00 2001 From: Sergio Moraes Date: Thu, 25 Feb 2021 14:56:47 -0800 Subject: [PATCH] n/a --- Python/Scraper/SergieZackScraperChanges.py | 76 ++++++ Python/hello world.py | 8 + Python/multiplesof3and5.py | 0 Python/test.py | 0 picamera-4-microscope_Touchphat-+images.py | 222 ++++++++++++++++ ...a-4-microscope_vers_3_Touchphat_hispeed.py | 240 ++++++++++++++++++ 6 files changed, 546 insertions(+) create mode 100644 Python/Scraper/SergieZackScraperChanges.py create mode 100644 Python/hello world.py create mode 100644 Python/multiplesof3and5.py create mode 100644 Python/test.py create mode 100644 picamera-4-microscope_Touchphat-+images.py create mode 100644 picamera-4-microscope_vers_3_Touchphat_hispeed.py diff --git a/Python/Scraper/SergieZackScraperChanges.py b/Python/Scraper/SergieZackScraperChanges.py new file mode 100644 index 0000000..a630c02 --- /dev/null +++ b/Python/Scraper/SergieZackScraperChanges.py @@ -0,0 +1,76 @@ +import requests +import pandas as pd +from bs4 import BeautifulSoup +import re +import time +import random + +#Gets the website that will be scraped and creates a soup. +result = requests.get('https://www.quickenloans.com/mortgage-glossary', verify=False, timeout=1) + +soup = BeautifulSoup(result.content, "html") + + +#Extract links from the given url (https://www.quickenloans.com/mortgage-glossary) /mortgage-glossary +glossaryLinksList = soup.findAll('a', attrs={'href': re.compile("^/mortgage-glossary")}) +linksHolder1 = [] +for link in glossaryLinksList: + linksHolder1.append("https://www.quickenloans.com/"+link.get('href')) + +#linksHolder1 + +#Links from each letter page + +pageLinkList = [] +for link in linksHolder1: + result2 = requests.get(link, verify=False, timeout=1) + soup2 = BeautifulSoup(result2.content, "html") + for item1 in soup2.find_all(class_="termList"): + for link in item1.find_all('a'): + pageLinkList.append("https://www.quickenloans.com/"+link.get('href')) + + + + +result2 = requests.get('https://www.quickenloans.com//mortgage-glossary/b', verify=False, timeout=1) +soup2 = BeautifulSoup(result2.content, "html") +pageLinkList = [] +for item1 in soup2.find_all(class_="termList"): + for link in item1.find_all('a'): + pageLinkList.append("https://www.quickenloans.com/"+link.get('href')) + + + + + +#pageLinkList + +pageLinkList + + + +DefinitionsDict = dict() + + + +for wee in pageLinkList[1:260]: + result3 = requests.get(wee, verify=False, timeout=1) + soup3 = BeautifulSoup(result3.content, "html") + for h in soup3.find_all('h1'): + Term = h.text + Definition = soup3.find('p') + DefinitionsDict.update({Term:Definition.text}) + time.sleep(random.randint(1,5)) + print(Term+Definition.text) + + + + + +DefinitionsDict + + + +Glossary = pd.DataFrame.from_dict(DefinitionsDict, orient="index") + +Glossary.to_excel("testsergie.xlsx") diff --git a/Python/hello world.py b/Python/hello world.py new file mode 100644 index 0000000..30dd109 --- /dev/null +++ b/Python/hello world.py @@ -0,0 +1,8 @@ +a = 2 +print "hello world" +print a +import matplotlib + +print -(-(-(-2))) == -2 and 4 >= 16**0.5 +print 19 % 4 != 300 / 10 / 10 and False +print 2 + 2 and 3 + 3p diff --git a/Python/multiplesof3and5.py b/Python/multiplesof3and5.py new file mode 100644 index 0000000..e69de29 diff --git a/Python/test.py b/Python/test.py new file mode 100644 index 0000000..e69de29 diff --git a/picamera-4-microscope_Touchphat-+images.py b/picamera-4-microscope_Touchphat-+images.py new file mode 100644 index 0000000..a53d89d --- /dev/null +++ b/picamera-4-microscope_Touchphat-+images.py @@ -0,0 +1,222 @@ +''' +A module "picamera"-based script for the Raspberry Pi HQ camera microscope, +controlled by a Pimoroni Touchphat + +Install required libraries before use +''' + +from time import sleep +import picamera +import datetime as dt +import touchphat +import os +#from guizero import App, Text, TextBox, Picture, Slider, PushButton +#import gpiozero # for a physical button control version +#import signal +#import subprocess +#import sys + + +w_dir = os.getcwd() +print ('working directory: ', w_dir) + +camera = picamera.PiCamera() #turns camera on + +#General camera settings: loads of parameters to play with +camera.rotation= 180 # 90,180,270 +#camera.hflip = True # default: False +#camera.vflip = True # default: False + +camera.meter_mode = 'spot' # optimize illumination, +# alternative options: 'average', 'backlit', 'matrix', 'spot' + +camera. awb_mode = 'auto' # automatic whithe balance.. You may play with setting fitting best to your setting +# alternatives: off, auto, sunlight, cloudy, shade, tungsten, fluorescent, incandelescent, flash, horizon, greyworld + +#camera.iso =100 # 200,400, 800 +#camera.contrast = 0.5 # +camera.brightness = 50 # 0 ...100, default 50 +camera.sharpness = 0 #-100 to 100, default 0 + +# set annotation format in images +camera.annotate_background = picamera.Color ('blue') # sets background color for text +#camera.annotate_foreground = picamera.Color (Y=1, U=0, V=0) # sets brightness for text Y=0..1 + +#select effects to apply while capturing image +effect1 = 'negative' #Touchpad "C" +effect2 = 'colorbalance' #Touchpad "D" +''' +#further options: negative, solarize, sketch, denoise, emboss, oilpaint, hatch, pastel, watercolor, film, blur, saturation, colorswap, washedout, posterize, colorpoint, colorbalance, cartoon, deinterlace1, deinterlace2 +''' +#preview settings +preview_time_1 = 8 # duration for displaying preview in sec: +#for total view: optimize object placing & focus +preview_time_2 = 8 # +#for total view emboss: fine tuning +preview_time_3 = 8 +#for ROI-view: fine tuning + +#image capture settings +delay_time = 2 # delay between images taken, in sec + +#video length settings + +vga_time = 30 # for 640x480 video +hires_time = 20 # for 1080p video + +# define position and size of preview window +preview_xy = (800,300) #position of upper left corner of preview window on screen +preview_size = (1014, 760) # size of preview window, here: 1/4 of max resolution HQ camera + +#Zeitpunkt = "" # set as general variable for timestamp text + +#check for type of camera installed +camera_version = camera.revision +print ('camera type: ', camera_version) +if (camera_version == 'imx477'): + print ('HQ camera detected') + print ('Modus 1: 2028 x 1080, Modus 2: 2028x1520, Modus 3: 4056x3040, Modus 4: 1012x760') + modus = 3 + camera.sensor_mode = modus + print ('Activated modus: ', modus) + camera.resolution = (1014,760) # defines image size + print ('Image size: ', camera.resolution) + camera.framerate = 15 # 30 + print ('Framerate set to: ', camera.framerate, 'fps') + +elif (camera.version == 'ov5647'): + print ('version 1 camera detected') + print ('modus 1: 1080p (30 fps), modi 2/3: 2592x1944, modus 4: 1296x972, modus 5: 1296x730, modi 6/7: VGA (60/90 fps)') + print ('code may require some adaptation') + camera.resolution = (1014,760) # defines image size + print ('Image size: ', camera.resolution) + camera.framerate = 30 + +elif (camera.version == 'imx219'): + print ('version 2 camera detected') + print ('Settings may require some adjustments') + print ('modus 1: 1080p (30 fps), modi 2/3: 3280x2464 (15), modus 4: 1640x1232 (40), modus 5: 1640x922, modus 6: 720p (90), modus 7: VGA (90)') + print ('code may require some adaptation') + camera.resolution = (1014,760) # defines image size + print ('Image size: ', camera.resolution) + camera.framerate = 30 + +else: + print ('No HQ camera! Please modify settings manually') # code to be optimized for version 2 camera + +# determine timestamp +def get_zeitpunkt(): + Time_info = dt.datetime.now().strftime('%Y-%m-%d %H:%M') + print ('Timestamp: ', Time_info) + return Time_info + +#Routines for preview and taking images, evoked by touckphat + +@touchphat.on_release('Enter') # button 'Enter' evokes Preview total for previewtime 1 seconds +def preview_ROI_none(): + touchphat.led_on(6) + camera.zoom = (0.375, 0.375, 0.25, 0.25) #restrict to ROI: central 25 %, equals maximal resolution + camera.annotate_text = 'Preview ROI' + sleep (preview_time_3) + camera.zoom = (0,0,0,0) + camera.annotate_text ='Preview total' + touchphat.led_off(6) + +''' #not used here +def preview_Total_emboss(): + touchphat.led_on(1) + camera.image_effect =('emboss') # 'none, 'cartoon', 'negative','sketch', 'emboss' ... + camera.annotate_text = "Preview - emboss" + sleep (preview_time_2) + camera.image_effect =('none')# back to standard + touchphat.led_off(1) +''' +@touchphat.on_release('A') # button 'A' evokes taing image of total area, no effects +def take_Total_none(): # take image of tolal view without applying any effect + touchphat.led_on(2) + Zeitpunkt = get_zeitpunkt() + Image_text = Zeitpunkt + ' - Total-none' + camera.annotate_text = Image_text + camera.capture (Image_text + '.jpg') # get total image, store as jpg + print ('Image taken: ',Image_text) + camera.annotate_text ='Preview total area' + touchphat.led_off(2) + +@touchphat.on_release('B') # button 'B' evokes taing image of ROI, no effects +def take_ROI_none(): #take image of ROI applying no effect + # zoom to ROI + camera.zoom = (0.375, 0.375, 0.25, 0.25) #restrict to ROI: central 25 %, equals maximal resolution + sleep (2) + Zeitpunkt = get_zeitpunkt() + Image_text = Zeitpunkt + ' - ROI-none' # for unmodified image + camera.annotate_text = Image_text + camera.capture (Image_text +'.png') # store as png to reduce loss of information + print ('Image taken: ',Image_text) + camera.zoom = (0, 0, 0, 0) + camera.annotate_text ='Preview total area' + +@touchphat.on_release('C') # button 'C' evokes taking image of ROI, effect1 applied +def take_ROI_effect1(): #take image of ROI applying effect1 + camera.zoom = (0.375, 0.375, 0.25, 0.25) #restrict to ROI: central 25 %, equals maximal resolution + camera.image_effect = effect1 + sleep (1) + Zeitpunkt = get_zeitpunkt() + Image_text = Zeitpunkt + ' - ROI-' + effect1 + camera.annotate_text = Image_text + camera.capture (Image_text +'.png') # store as png to reduce loss of information + print ('Image taken: ',Image_text) + camera.image_effect = 'none' + camera.zoom = (0, 0, 0, 0) + camera.annotate_text ='Preview total area' + +@touchphat.on_release('D') # button 'D' evokes taking image of ROI, effect2: posterize applied +def take_ROI_effect2(): #take image of ROI applying effect = 'xxx' + camera.zoom = (0.375, 0.375, 0.25, 0.25) #restrict to ROI: central 25 %, equals maximal resolution + camera.image_effect = effect2 + sleep (1) + Zeitpunkt = get_zeitpunkt() + Image_text = Zeitpunkt + ' - ROI-'+ effect2 + camera.annotate_text = Image_text + camera.capture (Image_text +'.png') # store as png to reduce loss of information + print ('Image taken: ',Image_text) + camera.image_effect = 'none' + camera.zoom = (0, 0, 0, 0) + camera.annotate_text ='Preview total area' + +@touchphat.on_release('Back') # button 'Back' evokes end of programm and cleaning of memory +def end_camera(): #end routine + touchphat.led_on(1) + camera.stop_preview() + camera.close () # close camera, free storage + print ("Camera closed") + sleep (1) + touchphat.led_off(1) + print ('Stop script now manually!') # how to stop all processes from tread? + #sys.exit() + #quit() + #exit() + +#instructions for use +print () +print ('On Touch phat press: ') +print (' "Enter" (right side) for a 10 sec preview of ROI (no effect applied)') +print (' "A" to take an image of total area, no effect applied') +print (' "B" to take an image of ROI, no effect applied') +print (' "C" to take an image of ROI, effect1 "', effect1, '" applied') +print (' "D" to take an image of ROI, effect2 "', effect2, '" applied') +print (' "Back" (left side) to end program') +print () + +#start with total area preview w/o effects applied +#camera warm-up time 3 sec +touchphat.all_on() # turn all LEDs on +sleep (1) +touchphat.all_off() # turn them off + +#start preview +camera.start_preview() +camera.preview.fullscreen = False # enables display of preview in defined window +camera.preview.window = (preview_xy[0], preview_xy[1], preview_size[0], preview_size[1]) # defines position of upper left corner and size of display window +camera.annotate_text = 'Preview total area' +#sleep (preview_time_1) + diff --git a/picamera-4-microscope_vers_3_Touchphat_hispeed.py b/picamera-4-microscope_vers_3_Touchphat_hispeed.py new file mode 100644 index 0000000..83bd31f --- /dev/null +++ b/picamera-4-microscope_vers_3_Touchphat_hispeed.py @@ -0,0 +1,240 @@ +#!/usr/bin/env python + + +''' +A module "picamera"-based script for the Raspberry Pi HQ camera microscope, +controlled by a Pimoroni Touchphat + +Install required libraries before use + +Runs in Mode 4 for low-res high speed videos +''' +from time import sleep +import picamera +import datetime as dt +import touchphat +import os +#from guizero import App, Text, TextBox, Picture, Slider, PushButton +#import gpiozero # for a physical button control version +#import signal +#import subprocess +#import sys + + +w_dir = os.getcwd() +print ('working directory: ', w_dir) + +camera = picamera.PiCamera() #turns camera on + +#General camera settings: loads of parameters to play with +camera.rotation= 180 # 90,180,270 +#camera.hflip = True # default: False +#camera.vflip = True # default: False + +camera.meter_mode = 'spot' # optimize illumination, +# alternative options: 'average', 'backlit', 'matrix', 'spot' + +camera. awb_mode = 'auto' # automatic whithe balance.. You may play with setting fitting best to your setting +# alternatives: off, auto, sunlight, cloudy, shade, tungsten, fluorescent, incandelescent, flash, horizon, greyworld + +#camera.iso = 100 # 200,400, 800 +#camera.contrast = 0.5 # +camera.brightness = 50 # 0 ...100, default 50 +camera.sharpness = 0 #-100 to 100, default 0 + +# set annotation format in images +camera.annotate_background = picamera.Color ('blue') # sets background color for text +#camera.annotate_foreground = picamera.Color (Y=1, U=0, V=0) # sets brightness for text Y=0..1 + +#select effects to apply while capturing image +effect1 = 'emboss' #Touchpad "C" +effect2 = 'solarize' #Touchpad "D" +''' +#further options: negative, solarize, sketch, denoise, emboss, oilpaint, hatch, pastel, watercolor, film, blur, saturation, colorswap, washedout, posterize, colorpoint, colorbalance, cartoon, deinterlace1, deinterlace2 +''' +#preview settings +preview_time_1 = 8 # duration for displaying preview in sec: +#for total view: optimize object placing & focus +preview_time_2 = 8 # +#for total view emboss: fine tuning +preview_time_3 = 8 +#for ROI-view: fine tuning + +#image capture settings +delay_time = 2 # delay between images taken, in sec + +#video length settings +vga_time = 5 # for 506x380 video +hires_time = 5 # for 1012x760 video + +# define position and size of preview window +preview_xy = (800,300) #position of upper left corner of preview window on screen +preview_size = (1012, 760) # size of preview window, here: 1/4 of max resolution HQ camera + +#Zeitpunkt = "" # set as general variable for timestamp text + +#check for type of camera installed +camera_version = camera.revision +print ('camera type: ', camera_version) +if (camera_version == 'imx477'): + print ('HQ camera detected') + print ('Modus 1: 2028 x 1080 (1-50 fps), Modus 2: 2028x1520 (1-50), Modus 3: 4056x3040 (up to 10), Modus 4: 1012x760 (50 - 120)') + modus = 4 + camera.sensor_mode = modus + print ('Activated modus: ', modus) + camera.resolution = (1012,760) # defines image size + print ('Image size: ', camera.resolution) + camera.framerate = 60 # Mode 4: 51 - 120 + print ('Framerate set to: ', camera.framerate, 'fps') + +elif (camera.version == 'ov5647'): + print ('version 1 camera detected') + print ('modus 1: 1080p (30 fps), modi 2/3: 2592x1944, modus 4: 1296x972, modus 5: 1296x730, modi 6/7: VGA (60/90 fps)') + print ('code may require some adaptation') + camera.resolution = (1014,760) # defines image size + print ('Image size: ', camera.resolution) + camera.framerate = 30 + +elif (camera.version == 'imx219'): + print ('version 2 camera detected') + print ('Settings may require some adjustments') + print ('modus 1: 1080p (30 fps), modi 2/3: 3280x2464 (15), modus 4: 1640x1232 (40), modus 5: 1640x922, modus 6: 720p (90), modus 7: VGA (90)') + print ('code may require some adaptation') + camera.resolution = (1014,760) # defines image size + print ('Image size: ', camera.resolution) + camera.framerate = 30 + +else: + print ('No HQ camera! Please modify settings manually') # code to be optimized for version 2 camera + +# determine timestamp +def get_zeitpunkt(): + Time_info = dt.datetime.now().strftime('%Y-%m-%d %H:%M') + print ('Timestamp: ', Time_info) + return Time_info + +#Routines for preview and taking images, evoked by touckphat + +@touchphat.on_release('Enter') # button 'Enter' evokes Preview total for previewtime 1 seconds +def preview_ROI_none(): + touchphat.led_on(6) + camera.zoom = (0.375, 0.375, 0.25, 0.25) #restrict to ROI: central 25 %, equals maximal resolution + #camera.preview.crop = (380, 285, 253, 190) # starting points for and size of selection: central 25% + camera.annotate_text = 'Preview ROI' + sleep (preview_time_3) + #camera.preview.crop = (0, 0, preview_size[0], preview_size[1]) #back to normal + camera.zoom = (0,0,0,0) + camera.annotate_text ='' + touchphat.led_off(6) + +''' #not used here +def preview_Total_emboss(): + touchphat.led_on(1) + camera.image_effect =('emboss') # 'none, 'cartoon', 'negative','sketch', 'emboss' ... + camera.annotate_text = "Preview - emboss" + sleep (preview_time_2) + camera.image_effect =('none')# back to standard + touchphat.led_off(1) +''' +@touchphat.on_release('A') # button 'A' evokes taing image of total area, no effects +def take_Total_none(): # take image of tolal view without applying any effect + touchphat.led_on(2) + Zeitpunkt = get_zeitpunkt() + Image_text = Zeitpunkt + ' - overview' + camera.annotate_text = Image_text + camera.capture (Image_text + '.jpg') # get total image, store as jpg + print ('Image taken: ',Image_text) + camera.annotate_text ='Preview total' + touchphat.led_off(2) + +@touchphat.on_release('B') # button 'B' evokes taing image of ROI, no effects +def take_ROI_none(): #take image of ROI applying no effect + # zoom to ROI + touchphat.led_on(3) + camera.zoom = (0.375, 0.375, 0.25, 0.25) #restrict to ROI: central 25x25 %, equals maximal resolution + sleep (2) + Zeitpunkt = get_zeitpunkt() + Image_text = Zeitpunkt + ' - ROI-none' # for unmodified image + camera.annotate_text = Image_text + camera.capture (Image_text +'.png') # store as png to reduce loss of information + print ('Image taken: ',Image_text) + camera.zoom = (0, 0, 0, 0) + camera.annotate_text ='Preview total' + touchphat.led_off(3) + +@touchphat.on_release('C') # button 'C' evokes taking lores high speed video +def take_hispeed_video(): #low res high framerate video + touchphat.led_on(4) + camera.resolution = (253, 190) #(506, 380) + #camera.zoom = (0.375, 0.375, 0.25, 0.25) #restrict to ROI: central 25 %, equals maximal resolution + camera.framerate = 120 # max 120 fps in mode 4 + Zeitpunkt = get_zeitpunkt() + video_name = Zeitpunkt + '_hispeed.h264' + camera.annotate_text = 'hispeed' + print ('start recording') + camera.start_recording(video_name) + camera.wait_recording(vga_time) + camera.stop_recording() + print ('recording stopped') + #camera.zoom = (0, 0, 0, 0) + camera.resolution =(1012,760) # back to total view + camera.framerate = 60 # back to normal speed + camera.annotate_text = 'Preview Total' + #camera.start_preview() + touchphat.led_off(4) + + +@touchphat.on_release('D') # button 'D' evokes taking total area video +def take_video_total(): + touchphat.led_on(5) + Zeitpunkt = get_zeitpunkt() + video_name = Zeitpunkt + '_largevid.h264' + camera.annotate_text = 'total area.' + print ('start recording') + camera.start_recording(video_name) + camera.wait_recording(hires_time) + camera.stop_recording() + print ('stop recording') + + camera.annotate_text = 'Preview total' + touchphat.led_off(5) + + + +@touchphat.on_release('Back') # button 'Back' evokes end of programm and cleaning of memory +def end_camera(): #end routine + touchphat.led_on(1) + camera.stop_preview() + camera.close () # close camera, free storage + print ("Camera closed") + sleep (1) + touchphat.led_off(1) + print ('Stop script now manually!') # how to stop all processes from tread? + #sys.exit() + #quit() + #exit() + +#instructions for use +print () +print ('On Touch phat: ') +print (' press "Enter" (right side) for a 10 sec preview of ROI (no effect applied)') +print (' press "A" to take an image of total area, no effect applied') +print (' press "B" to take an image of ROI, no effect applied') +print (' press "C" to take a video, 120 fps, ROI resolution') +print (' press "D" to take a video 60 fps, total area') +print (' press "Back" (left side) to terminate program') +print () + +#start with total area preview w/o effects applied +#camera warm-up time 3 sec +touchphat.all_on() # turn all LEDs on +sleep (3) +touchphat.all_off() # turn them off + +#start preview +camera.start_preview() +camera.preview.fullscreen = False # enables display of preview in defined window +camera.preview.window = (preview_xy[0], preview_xy[1], preview_size[0], preview_size[1]) # defines position of upper left corner and size of display window +camera.annotate_text = 'Preview total area' +#sleep (preview_time_1) +