How to use get_sy method in avocado

Best Python code snippet using avocado_python

sendmsg.py

Source: sendmsg.py Github

copy

Full Screen

1import socket2import time3import cv24import numpy as np5cap = cv2.VideoCapture(0)6cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)7cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)8print("start camera...")9time.sleep(1)10#connection set up11HOST = '192.168.1.6' #**check host ip12PORT = 800113sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)14sock.bind((HOST, PORT))15sock.listen(5)16#parameters for pose estimation17mtx = np.array([[862.95693399, 0., 355.06015428],18 [0., 859.4439399, 228.77007565],19 [0., 0., 1.]])20dist = np.array([5.59745642e-02, -1.10551114e+01, -4.63555574e-05, -3.08611069e-03,21 4.56662196e+01])22last_sx=float('inf')23last_sy=float('inf')24#get position of 'object', 'obstacles', and 'goal'25def get_position():26 global last_sx27 global last_sy28 get_sx = float('inf')29 get_sy = float('inf')30 get_gx = float('inf')31 get_gy = float('inf')32 get_ox = []33 get_oy = []34 ret, frame = cap.read()35 gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)36 dictionary = cv2.aruco.Dictionary_get(cv2.aruco.DICT_6X6_250)37 parameters = cv2.aruco.DetectorParameters_create()38 markerCorners, markerIds, rejectedCandidates = cv2.aruco.detectMarkers(gray, dictionary, parameters=parameters)39 if markerIds is not None:40 # ret=(array(rvec),array(tvec),array(_))41 ret = cv2.aruco.estimatePoseSingleMarkers(markerCorners, 0.066, mtx, dist)42 # ---rvec:rotation vector, attitude of marker respect to camera frame43 # ---rvec=[[[rvec_1, rvec_2,...]]]44 # ---tvec:translation vector, position of marker in camera frame45 # ---tvec=[[[tvec_1, tvec_2...]]]46 for i in range(len(markerIds)):47 rvec = ret[0][i][0]48 tvec = ret[1][i][0]49 #object position50 if markerIds[i] == 33:51 get_sx = tvec[1] * 100 #*100:change unit form m to cm52 get_sy = tvec[0] * 10053 #print("sx:", get_sx, "sy:", get_sy)54 #goal position55 elif markerIds[i] == 20:56 get_gx = tvec[1] * 10057 get_gy = tvec[0] * 10058 #print("gx:", get_gx, " gy:", get_gy)59 else:60 #obstacles position61 x = tvec[1] * 10062 y = tvec[0] * 10063 get_ox.append(x)64 get_oy.append(y)65 cv2.aruco.drawAxis(frame, mtx, dist, rvec, tvec, 0.03)66 cv2.aruco.drawDetectedMarkers(frame, markerCorners, markerIds, (0, 0, 255))67 if get_sx != float('inf') and get_sy != float('inf') :68 last_sx = get_sx69 last_sy = get_sy70 else:71 get_sx=last_sx72 get_sy=last_sy73 print("No object and goal !!!!")74 else:75 cv2.putText(frame, "No Ids", (0, 64), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2, cv2.LINE_AA)76 cv2.imshow("frame", frame)77 cv2.waitKey(1)78 return get_sx, get_sy, get_gx, get_gy, get_ox, get_oy79ok=True80#make sure goal and object are detected81while ok:82 sx, sy, gx, gy, ox, oy = get_position()83 if sx != float('inf') and sy != float('inf') and gx != float('inf') and gy != float('inf'):84 ok=False85set=True86while True:87 sx, sy, gx, gy, ox, oy=get_position()88 #detecting start points89 if set:90 ori_gx=gx91 ori_gy=gy92 ori_ox=ox93 ori_oy=oy94 set=False95 a=[int(sx), int(sy), int(ori_gx), int(ori_gy)]96 #add obstacles97 for z in range(len(ori_ox)):98 a.append(int(ori_ox[z]))99 a.append(int(ori_oy[z]))100 a.append('s')101 print("position_array=",a)102 #send message103 for i in range(len(a)):104 connection, address = sock.accept()105 try:106 connection.settimeout(10)107 buf = connection.recv(1024)108 if buf:109 msg = str(a[i])110 print("msg=",msg)111 connection.send(bytearray(msg.encode()))112 print('Sending success!')113 else:114 connection.send(b'please go out!')115 except socket.timeout:116 print('time out')...

Full Screen

Full Screen

game.py

Source: game.py Github

copy

Full Screen

...4def draw_sqr(square):5 pygame.draw.rect(surface,6 BLACK,7 pygame.Rect(square.get_sx(),8 square.get_sy(),9 square.get_radius(),10 square.get_radius()11 )12 )13BLACK = (0, 0, 0)14WHITE = (255, 255, 255)15pygame.init()16size = (1000, 600)17surface = pygame.display.set_mode(size)18pygame.display.set_caption("Agar")19squares = []20player = Square(1, 50, 50, 50)21for i in range(100):22 square = Square(i + 2, 10, random.randint(0, 1000), random.randint(0, 600))23 squares.append(square)24running = True25clock = pygame.time.Clock()26while running:27 # --- Main event loop28 for event in pygame.event.get():29 if event.type == pygame.QUIT:30 running = False31 if event.type == pygame.KEYDOWN:32 if event.key == pygame.K_LEFT:33 player.set_sx(player.get_sx() - 5)34 if event.key == pygame.K_RIGHT:35 player.set_sx(player.get_sx() + 5)36 if event.key == pygame.K_UP:37 player.set_sy(player.get_sy() - 5)38 if event.key == pygame.K_DOWN:39 player.set_sy(player.get_sy() + 5)40 if event.key == pygame.K_SPACE:41 print(3)42 surface.fill(WHITE)43 for square in squares:44 if (player.get_sx() <= square.get_sx() <= player.get_sx() + player.get_radius() - square.get_radius()45 and player.get_sy() <= square.get_sy() <= player.get_sy() + player.get_radius() - square.get_radius()):46 player.set_radius(player.get_radius() + square.get_radius())47 squares.remove(square)48 draw_sqr(player)49 for square in squares:50 draw_sqr(square)51 pygame.display.flip()52 clock.tick(60)...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Nov’22 Updates: Live With Automation Testing On OTT Streaming Devices, Test On Samsung Galaxy Z Fold4, Galaxy Z Flip4, &#038; More

Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.

Considering Agile Principles from a different angle

In addition to the four values, the Agile Manifesto contains twelve principles that are used as guides for all methodologies included under the Agile movement, such as XP, Scrum, and Kanban.

How To Choose The Best JavaScript Unit Testing Frameworks

JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.

How To Write End-To-End Tests Using Cypress App Actions

When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.

[LambdaTest Spartans Panel Discussion]: What Changed For Testing &#038; QA Community And What Lies Ahead

The rapid shift in the use of technology has impacted testing and quality assurance significantly, especially around the cloud adoption of agile development methodologies. With this, the increasing importance of quality and automation testing has risen enough to deliver quality work.

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful