Best Python code snippet using avocado_python
Laba_2.py
Source:Laba_2.py
...73 cv2.namedWindow('Display window', cv2.WINDOW_NORMAL)74 cv2.imshow('Display window', ver)75 cv2.waitKey(0)76 cv2.destroyAllWindows()77def display_images_list(imgarray):78 rows = len(imgarray) # Ðлина коÑÑежа или ÑпиÑка79 cols = len(imgarray[80 0]) # ÐÑли imgarray - ÑÑо ÑпиÑок, веÑнÑÑÑ ÐºÐ¾Ð»Ð¸ÑеÑÑво каналов пеÑвого изобÑÐ°Ð¶ÐµÐ½Ð¸Ñ Ð² ÑпиÑке, еÑли ÑÑо коÑÑеж, веÑнÑÑÑ Ð´Ð»Ð¸Ð½Ñ Ð¿ÐµÑвого ÑпиÑка, ÑодеÑжаÑегоÑÑ Ð² коÑÑеже81 # print("rows=", rows, "cols=", cols)82 # ÐаÑÑÑабиÑÑемоÑÑÑ83 scale = 184 # ШиÑина и вÑÑоÑа пеÑвой каÑÑинки85 width = imgarray[0].shape[1]86 height = imgarray[0].shape[0]87 # print("width=", width, "height=", height)88 # ÐпеÑаÑÐ¸Ñ ÑÑанÑÑоÑмаÑии, как и ÑанÑÑе89 for x in range(0, rows):90 if imgarray[x].shape[:2] == imgarray[0].shape[:2]:91 imgarray[x] = cv2.resize(imgarray[x], (0, 0), None, scale, scale)92 else:93 imgarray[x] = cv2.resize(imgarray[x], (imgarray[0].shape[1], imgarray[0].shape[0]), None, scale, scale)94 # РаÑположиÑÑ ÑпиÑок по гоÑизонÑали95 hor = np.hstack(imgarray)96 ver = hor97 cv2.namedWindow('Display window', cv2.WINDOW_NORMAL)98 cv2.imshow('Display window', ver)99 cv2.waitKey(0)100 cv2.destroyAllWindows()101def dis(imgarray):102 scale = 0.5103 rows = len(imgarray) # Ðлина коÑÑежа или ÑпиÑка104 cols = len(imgarray[105 0]) # ÐÑли imgarray - ÑÑо ÑпиÑок, веÑнÑÑÑ ÐºÐ¾Ð»Ð¸ÑеÑÑво каналов пеÑвого изобÑÐ°Ð¶ÐµÐ½Ð¸Ñ Ð² ÑпиÑке, еÑли ÑÑо коÑÑеж, веÑнÑÑÑ Ð´Ð»Ð¸Ð½Ñ Ð¿ÐµÑвого ÑпиÑка, ÑодеÑжаÑегоÑÑ Ð² коÑÑеже106 print("rows= ", rows, "cols=", cols)107 # ÐпÑеделиÑÑ, ÑвлÑеÑÑÑ Ð»Ð¸ Ñип imgarray [0] ÑпиÑком108 # СпиÑок, ÑказÑваÑÑий, ÑÑо imgarray ÑвлÑеÑÑÑ ÐºÐ¾ÑÑежем и должен оÑобÑажаÑÑÑÑ Ð²ÐµÑÑикалÑно109 rowsAvailable = isinstance(imgarray[0], list)110 # ШиÑина и вÑÑоÑа пеÑвой каÑÑинки111 width = imgarray[0][0].shape[1]112 height = imgarray[0][0].shape[0]113 print("width=", width, "height=", height)114 # ÐÑли вÑ
одÑÑий коÑÑеж115 if rowsAvailable:116 for x in range(0, rows):117 for y in range(0, cols):118 # ÐбойÑи коÑÑеж, еÑли ÑÑо пеÑвое изобÑажение, не пÑеобÑазовÑваÑÑ119 if imgarray[x][y].shape[:2] == imgarray[0][0].shape[:2]:120 imgarray[x][y] = cv2.resize(imgarray[x][y], (0, 0), None, scale, scale)121 # ÐÑеобÑазÑйÑе дÑÑгие маÑÑиÑÑ Ðº ÑÐ¾Ð¼Ñ Ð¶Ðµ ÑазмеÑÑ, ÑÑо и пеÑвое изобÑажение, и коÑÑÑиÑÐ¸ÐµÐ½Ñ Ð¼Ð°ÑÑÑабиÑÐ¾Ð²Ð°Ð½Ð¸Ñ Ð±ÑÐ´ÐµÑ Ð¼Ð°ÑÑÑабиÑоваÑÑÑÑ122 else:123 imgarray[x][y] = cv2.resize(imgarray[x][y], (imgarray[0][0].shape[1], imgarray[0][0].shape[0]),124 None, scale, scale)125 # ÐÑли изобÑажение в оÑÑенкаÑ
ÑеÑого, пÑеобÑазоваÑÑ ÐµÐ³Ð¾ в ÑвеÑное оÑобÑажение126 if len(imgarray[x][y].shape) == 2:127 imgarray[x][y] = cv2.cvtColor(imgarray[x][y], cv2.COLOR_GRAY2BGR)128 # СоздайÑе пÑÑÑой Ñ
олÑÑ Ñого же ÑазмеÑа, ÑÑо и пеÑвое изобÑажение129 imgBlank = np.zeros((height, width, 3), np.uint8)130 hor = [131 imgBlank] * rows # Ð¢Ð¾Ñ Ð¶Ðµ ÑазмеÑ, ÑÑо и пеÑвое изобÑажение, и ÑÑолÑко же гоÑизонÑалÑнÑÑ
пÑÑÑÑÑ
изобÑажений, ÑколÑко коÑÑеж ÑодеÑÐ¶Ð¸Ñ ÑпиÑок132 for x in range(0, rows):133 # РаÑположиÑÑ x-й ÑпиÑок в коÑÑеже по гоÑизонÑали134 hor[x] = np.hstack(imgarray[x])135 ver = np.vstack(hor) # ÐбÑединиÑÑ ÑазнÑе ÑпиÑки по веÑÑикали136 # ÐÑли вÑ
одÑÑий - ÑÑо ÑпиÑок137 else:138 # ÐпеÑаÑÐ¸Ñ ÑÑанÑÑоÑмаÑии, как и ÑанÑÑе139 for x in range(0, rows):140 if imgarray[x].shape[:2] == imgarray[0].shape[:2]:141 imgarray[x] = cv2.resize(imgarray[x], (0, 0), None, scale, scale)142 else:143 imgarray[x] = cv2.resize(imgarray[x], (imgarray[0].shape[1], imgarray[0].shape[0]), None, scale, scale)144 if len(imgarray[x].shape) == 2:145 imgarray[x] = cv2.cvtColor(imgarray[x], cv2.COLOR_GRAY2BGR)146 # РаÑположиÑÑ ÑпиÑок по гоÑизонÑали147 hor = np.hstack(imgarray)148 ver = hor149 cv2.namedWindow('Display window', cv2.WINDOW_NORMAL)150 cv2.imshow('Display window', ver)151 cv2.waitKey(0)152 cv2.destroyAllWindows()153# РеализоваÑÑ ÑилÑÑÑ ÐаÑÑÑа ÑÑедÑÑвами ÑзÑка python154def task_1(img,n,sigma):155 # ÐзнаÑалÑное изобÑажение156 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)157 # ФилÑÑÑ ÐаÑÑÑа158 newGray = gauss(n, sigma, img)159 display_images_list([gray, newGray])160# ÐÑимениÑÑ Ð´Ð°Ð½Ð½Ñй ÑилÑÑÑ Ð´Ð»Ñ Ð´Ð²ÑÑ
ÑазнÑÑ
знаÑений ÑÑеднего квадÑаÑиÑного оÑклонениÑ161# и двÑÑ
ÑазнÑÑ
ÑазмеÑноÑÑей маÑÑиÑÑ ÑвеÑÑки, ÑÑавниÑÑ ÑезÑлÑÑаÑÑ Ð´Ð»Ñ ÐÐÐÐÐРизобÑажениÑ162def task_2(img):163 # ÐзнаÑалÑное изобÑажение164 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)165 newGray_1 = gauss(5,0.5,img)166 newGray_2 = gauss(7, 0.5, img)167 newGray_3 = gauss(3, 0.3, img)168 newGray_4 = gauss(3, 0.7, img)169 display_images_list([gray, newGray_1, newGray_2, newGray_3, newGray_4])170# РеализоваÑÑ ÑазмÑÑие ÐаÑÑÑа вÑÑÑоеннÑм меÑодом171# библиоÑеки OpenCV, ÑÑавниÑÑ ÑезÑлÑÑаÑÑ Ñ ÐаÑей ÑеализаÑией.172def task_3(img, n, sigma):173 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)174 # ÐÑÑÑоеннÑй меÑод175 img_blur = cv2.GaussianBlur(gray, (n, n), sigma)176 # ÐÐ¾Ñ ÑеализаÑиÑ177 image_my_blur = gauss(n, sigma, img)178 Blankimg = np.zeros((200, 200), np.uint8) # Ð Ð°Ð·Ð¼ÐµÑ Ð¼Ð¾Ð¶ÐµÑ Ð±ÑÑÑ Ð¿ÑинÑдиÑелÑно пÑеобÑазован лÑбой ÑÑнкÑией179 dis(([gray, gray], [img_blur, image_my_blur]))180def main():181 img = cv2.imread(r'2.jpg')182 n = 5183 sigma = 0.5...
vmimage.py
Source:vmimage.py
...60 file_path = image_info.base_image61 image = {'name': distro, 'version': image_info.version,62 'arch': image_info.arch, 'file': file_path}63 return image64def display_images_list(images):65 """66 Displays table with information about images67 :param images: list with image's parameters68 :type images: list of dicts69 """70 image_matrix = [[image['name'], image['version'], image['arch'],71 image['file']] for image in images]72 header = (output.TERM_SUPPORT.header_str('Provider'),73 output.TERM_SUPPORT.header_str('Version'),74 output.TERM_SUPPORT.header_str('Architecture'),75 output.TERM_SUPPORT.header_str('File'))76 for line in astring.iter_tabular_output(image_matrix, header=header,77 strip=True):78 LOG_UI.debug(line)79class VMimage(CLICmd):80 """81 Implements the avocado 'vmimage' subcommand82 """83 name = 'vmimage'84 description = 'Provides VM images acquired from official repositories'85 def configure(self, parser):86 parser = super(VMimage, self).configure(parser)87 subcommands = parser.add_subparsers(dest='vmimage_subcommand')88 subcommands.required = True89 subcommands.add_parser('list', help='List of all downloaded images')90 get_parser = subcommands.add_parser('get',91 help="Downloads chosen VMimage if "92 "it's not already in the "93 "cache")94 help_msg = 'Name of image distribution'95 settings.register_option(section='vmimage.get',96 key='distro',97 default=None,98 help_msg=help_msg,99 key_type=str,100 parser=get_parser,101 long_arg='--distro',102 required=True)103 help_msg = 'Image version'104 settings.register_option(section='vmimage.get',105 key='version',106 default=None,107 help_msg=help_msg,108 key_type=str,109 parser=get_parser,110 long_arg='--distro-version')111 help_msg = 'Image architecture'112 settings.register_option(section='vmimage.get',113 key='arch',114 default=None,115 help_msg=help_msg,116 key_type=str,117 parser=get_parser,118 long_arg='--arch')119 def run(self, config):120 subcommand = config.get("vmimage_subcommand")121 if subcommand == 'list':122 images = list_downloaded_images()123 display_images_list(images)124 elif subcommand == 'get':125 name = config.get('vmimage.get.distro')126 version = config.get('vmimage.get.version')127 arch = config.get('vmimage.get.arch')128 try:129 image = download_image(name, version, arch)130 except AttributeError:131 LOG_UI.debug("The requested image could not be downloaded")132 return exit_codes.AVOCADO_FAIL133 LOG_UI.debug("The image was downloaded:")134 display_images_list([image])...
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!!