Best Python code snippet using fMBT_python
FPVSystem.py
Source:FPVSystem.py
1import cv22import time3import base644import httplib25import time6import os7from googleapiclient import discovery8from oauth2client.client import GoogleCredentials9class FPVSystem:10 def __init__(self, secondsPerPhoto, numVehicle):11 self.secondsPerPhoto = secondsPerPhoto12 self.capture = None13 self.out = None14 self.numVehicle = numVehicle15 self.stopVideoCapture = False16 # The url template to retrieve the discovery document for trusted testers.17 self.discoveryURL = 'https://{api}.googleapis.com/$discovery/rest?version={apiVersion}'18 # [START authenticate]19 self.credentials = GoogleCredentials.get_application_default()20 self.service = discovery.build('vision', 'v1', credentials = self.credentials, discoveryServiceUrl = self.discoveryURL)21 # [END authenticate]22 print (chr(27) + "[0;32m" + "FPV System initiated."), ; print (chr(27) + "[0m") 23 def videoCapture(self):24 number = 025 cv2.namedWindow("Drone %s" %self.numVehicle, cv2.cv.CV_WINDOW_NORMAL)26 cv2.cv.ResizeWindow("Drone %s" %self.numVehicle, 640, 480)27 cv2.startWindowThread()28 while True:29 capAux = cv2.VideoCapture(number)30 if not (capAux.isOpened()):31 break;32 else:33 number= number+134 capAux.release()35 36 print number37 if number >= 1: 38 self.capture = cv2.VideoCapture(1)39 else:40 self.capture = cv2.VideoCapture(0)41 w = int(self.capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH))42 h = int(self.capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT))43 # video recorder44 fourcc = cv2.cv.CV_FOURCC(*'XVID')45 self.out = cv2.VideoWriter(time.strftime("Videos/%d-%m-%Y_%H:%M:%S")+".avi", fourcc, 25, (w, h))46 if not self.capture.isOpened():47 print chr(27) + "[0;31m" + "FPV system not connected.", ; print chr(27) + "[0m"48 t0 = time.time()49 result= ["Label not found"]50 while self.capture.isOpened() and not self.stopVideoCapture:51 coordY= 5052 ch = 0xFF & cv2.waitKey(1)53 ret, frame = self.capture.read()54 if ret == True:55 for i in result: 56 cv2.putText(frame, i, (20, coordY), cv2. FONT_HERSHEY_DUPLEX, 1.5, (0, 0, 255), 2)57 coordY = coordY + 5058 self.out.write(frame)59 cv2.imshow("Drone %s" %self.numVehicle,frame)60 timer = round((time.time() - t0) % self.secondsPerPhoto, 2)61 if timer >= 0 and timer <= 0.99:62 photoFile = time.strftime("Images/%d-%m-%Y_%H:%M:%S")+".jpg"63 cv2.imwrite(photoFile, frame)64 print chr(27) + "[1;33m" + "Drone %s: " %self.numVehicle + photoFile, "saved", ; print chr(27) + "[0m"65 result = self.labelDetection(photoFile, result) 66 else:67 break68 self.capture.release()69 self.out.release()70 cv2.destroyWindow("Drone %s" %self.numVehicle) 71 cv2.waitKey(1)72 cv2.waitKey(1)73 cv2.waitKey(1)74 cv2.waitKey(1)75 76 def labelDetection(self, photoFile, result):77 # [START construct_request]78 with open(photoFile, 'rb') as image:79 image_content = base64.b64encode(image.read())80 service_request = self.service.images().annotate(body = {81 'requests': [{82 'image': {83 'content': image_content.decode('UTF-8')84 },85 'features': [{86 'type': 'LABEL_DETECTION',87 'maxResults': 588 }]89 }]90 })91 # [END construct_request]92 93 # [START parse_response]94 response = service_request.execute()95 responseLength = len(response['responses'][0])96 if responseLength == 0:97 result = ["Label not found"]98 else:99 labelLength = len(response['responses'][0]['labelAnnotations'])100 result= []101 for i in range(labelLength):102 label = str(i+1) + ". " + response['responses'][0]['labelAnnotations'][i]['description']103 result.append(label)104 ...
teststeps.py
Source:teststeps.py
...21 return frames22def iStartVideocapt():23 camera.startVideoCapture()24def iStopVideocapt():...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!