How to use mouseleftclick method in pyatom

Best Python code snippet using pyatom_python

nugui.py

Source:nugui.py Github

copy

Full Screen

1import logging2llog = logging.getLogger(__name__) # the name 'log' is taken in sdl234import time56from OpenGL.GL import *7from copenglconstants import * # import to silence opengl enum errors for pycharm. pycharm can't see pyopengl enums.89from sdl2 import *101112class ListBox: pass1314class StateTextEntry:15 def __init__(self, id, clock, initial_text):16 self.cursor_pos = -117 self.clock = clock18 self.id = id19 self.initial_text = initial_text20 self.text = initial_text212223class NuGui:24 def __init__(self, font):25 """26 make sure you call this after calling gltext.init()27 font is a gltext instance28 """29 self.font = font3031 self.container_stack = []32 self.z = 100.33 self.listbox_item_height = self.font.height + 13435 # state3637 self.mouse_x = 0.38 self.mouse_y = 0.39 self.mousedown = False # left mouse button is down4041 self.mouseleftclickpos = (-1., -1.) # left button was pressed down at these coordinates42 self.mouseleftclicked = False # button went down and up. will be set to False on tick.43 self.mouseleftclick = False # button went down. will be set to False on tick.4445 self.slider_mouseleftclickpos = (-1., -1.) # left button was pressed down at these slider handle coordinates46 self.slider_mouseleftclick_val = 0.4748 self.id_active = 0 # mouse pressed49 self.id_hot = 0 # mouse hover50 self.id_focused = 05152 self.hit_clock = 053 # increased on every finish_frame() call54 self.current_clock = 055 self.focuslost_clock = 05657 # widget states. {id: state, ..}58 # temporary local state objects for complex ui elements. textedit for now59 self.states = {}6061 # the active element consumes keypresses from this queue.62 self.keyqueue = [] # [(character, scancode), ..]6364 def active(self):65 """return True if there's a work-in-progress mouse drag of some ui element."""66 return bool(self.id_active)6768 def finish_frame(self):69 # clear focus if there was a mouseclick outside of every gui element70 if self.hit_clock < self.current_clock and self.mousedown:71 self.focuslost_clock = self.current_clock72 self.id_focused = None73 self.current_clock += 17475 def begin_listbox(self, id, x, y, w=100.):76 """77 TODO: x, y - pixel-coordinates?78 """79 l = ListBox()80 l.x, l.y = x + 1, y + 181 l.w = w82 l.hc = 0. # h current83 self.container_stack.append( l )8485 def end_listbox(self):86 """87 return True if clicked out of the listbox.88 """89 l = self.container_stack.pop(-1)9091 # draw a box..9293 glDisable(GL_TEXTURE_2D)94 glLineWidth(1.)95 glColor4f(0., 0., 0., 1.)96 self._draw_rect(l.x - 2, l.y - 2, l.w + 4, l.hc + 3)9798 if self.mouseleftclicked:99 return not self._mouse_is_inside(l.x - 2, l.y - 2, l.w + 4, l.hc + 3)100 return False101102 def listbox_item(self, id, text, disabled=False, selected=False):103 l = self.container_stack[-1]104105 x, y, z, w, h = l.x, l.y + l.hc, self.z, l.w, self.font.height106107 if self._mouse_is_inside(x, y, w, h):108 self.id_hot = id109 if self.mousedown and not self.id_active:110 self.id_active = id111 self.id_focused = id112 if self.mousedown:113 self.hit_clock = self.current_clock114115 fgcolor = (0., 0., 0., 1.)116 if disabled:117 fgcolor = (0.5, 0.5, 0.5, 8.)118 glColor4f(0.8, 0.8, 1., 0.8)119 elif selected:120 if self.id_active == id: glColor4f(1., 0.0, 0.0, 0.95)121 elif self.id_hot == id: glColor4f(1., 0.4, 0.4, 0.95)122 else: glColor4f(0.8, 0.5, 0.7, 0.9)123 else:124 if self.id_active == id: glColor4f(1., 0.3, 0.3, 0.95)125 elif self.id_hot == id: glColor4f(1., 0.7, 0.7, 0.95)126 else: glColor4f(0.8, 0.8, 1., 0.9)127128 glDisable(GL_TEXTURE_2D)129 self._draw_filled_rect(x, y, w, h)130131 glEnable(GL_TEXTURE_2D)132 self.font.drawtl(text, x, y, z = z, fgcolor = fgcolor, bgcolor = (0., 0., 0., 0.))133134 l.hc += self.listbox_item_height135136 # did the user click the item?137138 if not disabled and self.id_hot == id and self.id_active == id and not self.mousedown: return True139 return False140141 def listbox_header(self, id, text):142 l = self.container_stack[-1]143144 x, y, z, w, h = l.x, l.y + l.hc, self.z, l.w, self.font.height145146 glColor4f(0.9, 0.9, 1., 0.93)147148 glDisable(GL_TEXTURE_2D)149 self._draw_filled_rect(x, y, w, h)150151 glEnable(GL_TEXTURE_2D)152 self.font.drawtl(text, x, y, z = z, fgcolor = (0., 0., 0., 1.), bgcolor = (0., 0., 0., 0.))153154 l.hc += self.listbox_item_height155156 def _get_element_color(self, id, disabled):157 """return fgcolor, bgcolor and textcolor. for button frame and background for example."""158 textcolor = (0., 0., 0., 1.)159 fgcolor = (0., 0., 0., 1.)160 if disabled:161 textcolor = (0.5, 0.5, 0.5, 1.0)162 bgcolor = (0.8, 0.8, 1.0, 0.8)163 elif self.id_active == id: bgcolor = (1.0, 0.3, 0.3, 0.95)164 elif self.id_hot == id: bgcolor = (1.0, 0.7, 0.7, 0.95)165 else: bgcolor = (0.8, 0.8, 1.0, 0.9)166167 return fgcolor, bgcolor, textcolor168169 def button(self, id, x, y, text, w=None, h=None, disabled=False):170 tw, z = self.font.width(text), self.z171 if w is None: w = tw + 10172 if h is None: h = self.font.height + 8173174 if self._mouse_is_inside(x, y, w, h):175 self.id_hot = id176 if self.mousedown and not self.id_active:177 self.id_active = id178 self.id_focused = id179 if self.mousedown:180 self.hit_clock = self.current_clock181182 # draw the button183184 fgcolor, bgcolor, textcolor = self._get_element_color(id, disabled)185186 glDisable(GL_TEXTURE_2D)187 glColor4f(*bgcolor)188 self._draw_filled_rect(x, y, w, h)189190 glColor4f(*fgcolor)191 self._draw_rect(x, y, w, h)192 glEnable(GL_TEXTURE_2D)193 glColor4f(*textcolor)194 self.font.drawmm(text, x + w / 2., y + h / 2., z = z, fgcolor=textcolor, bgcolor=(0., 0., 0., 0.))195196 # did the user click the button?197198 if not disabled and self.id_hot == id and self.id_active == id and not self.mousedown:199 return True200 return False201202 def listbox_item_menu(self, id, name, x, y, text): pass203204 def slider(self, id, x, y, w, val, val_left, val_right, disabled=False):205206 #mx, my = self.mouseclickpos207 #if self.mousedown:208 # self.slider_clickpos = self.mouseclickpos209 # self.mouse_x - self.mouseclickpos[0]210211212 handle_wpix = 7. # slider handle width in pixels213 handle_hpix = 12.214 val_wpix = w - handle_wpix215216217 # move the slider218 if self.id_active == id and not self.mouseleftclick:219 val_dxpix = self.mouse_x - self.mouseleftclickpos[0] #- self.slider_mouseleftclickpos[0]220 val = self.slider_mouseleftclick_val + val_dxpix / val_wpix * (val_right - val_left)221222223 val = min(val, val_right)224 val = max(val, val_left)225 if val_right - val_left == 0.:226 val_pix = 0.227 else:228 val_pix = (float(val) - val_left) / (val_right - val_left) * val_wpix229 val_pix += handle_wpix / 2.230 z = self.z231232 #llog.info("x %f y %f val %f w %f", x, y, val, w)233234 handle_x = x + val_pix - handle_wpix/2.235 handle_y = y - handle_hpix/2.236237238 if self._mouse_is_inside(handle_x, handle_y, handle_wpix, handle_hpix):239 self.id_hot = id240 if self.mousedown and not self.id_active:241 self.id_active = id242 self.id_focused = id243 if self.mousedown:244 self.hit_clock = self.current_clock245246 # if the button just went down, then record the click position.247 if self.mouseleftclick:248 self.slider_mouseleftclickpos = (self.mouse_x - handle_x, self.mouse_y - handle_y)249 self.slider_mouseleftclick_val = val250 llog.info("val %f", val)251252253 # self.mouseleftclickpos = (-1., -1.) # left button was pressed down at these coordinates254 # self.mouseleftclicked = False # button went down and up. will be set to False on tick.255 # self.mouseleftclick = False # button went down. will be set to False on tick.256257 # self.slider_mouseleftclickpos = (-1., -1.) # left button was pressed down at these slider handle coordinates258259 # if self._mouse_is_inside(handle_x, handle_y, handle_wpix, handle_hpix):260 # self.id_hot = id261 # if self.mousedown and not self.id_active:262 # self.id_active = id263 # self.id_focused = id264 # if self.mousedown:265 # self.hit_clock = self.current_clock266267 fgcolor, bgcolor, textcolor = self._get_element_color(id, disabled)268269 glColor4f(*fgcolor)270 glBegin(GL_LINES)271 glVertex3f(x, y + 0.5, z)272 glVertex3f(x + w, y + 0.5, z)273 # glVertex3f(x + 0.5, y + 0.5, z)274 # glVertex3f(x + 0.5 + w, y + 0.5, z)275 glEnd()276277 glColor4f(*bgcolor)278 self._draw_filled_rect(handle_x, handle_y, handle_wpix, handle_hpix)279280 glColor4f(*fgcolor)281 self._draw_rect(handle_x, handle_y, handle_wpix, handle_hpix)282283 return val284285 def textentry(self, id, x, y, w, default_text, disabled=False):286 """return (changed, new_text)287 changed is True if enter is pressed or focus is lost and the text is different from the initial default_text.288 disabled: flag not implemented289 """290 h = self.font.height + 8291 if self._mouse_is_inside(x, y, w, h):292 self.id_hot = id293 if self.mousedown and not self.id_active:294 self.id_active = id295 self.id_focused = id296 del self.keyqueue[:]297 if self.mousedown:298 self.hit_clock = self.current_clock299300 ret_changed = False301 ret_new_text = default_text302303 if self.id_focused == id:304 if id not in self.states:305 self.states[id] = StateTextEntry(id, self.current_clock, default_text)306 id_local = self.states[id]307 id_local.clock = self.current_clock308 assert id_local.id == id309310 for character, scancode in self.keyqueue:311 if scancode == SDL_SCANCODE_RETURN:312 if id_local.text != id_local.initial_text:313 ret_changed = True314 self.id_focused = None315 del self.states[id]316 break317 elif scancode == SDL_SCANCODE_ESCAPE:318 id_local.text = id_local.initial_text319 self.id_focused = None320 del self.states[id]321 break322 #elif scancode == SDL_SCANCODE_DELETE:323 elif scancode == SDL_SCANCODE_BACKSPACE:324 id_local.text = id_local.text[:-1]325 else:326 if character:327 id_local.text += character328329 ret_new_text = id_local.text330 del self.keyqueue[:]331 else:332 # check if focus was lost just last frame. in that case, generate a "changed" event.333 if id in self.states:334 llog.info("%s focus %s hit %s", self.states[id].clock, self.focuslost_clock, self.hit_clock)335 if self.states[id].clock == self.hit_clock - 1 or self.states[id].clock == self.focuslost_clock:336 ret_changed = True337 ret_new_text = self.states[id].text338 del self.states[id]339340341 fgcolor = (0., 0., 0., 1.)342 if disabled:343 fgcolor = (0.5, 0.5, 0.5, 8.)344 glColor4f(0.8, 0.8, 1., 0.8)345 elif self.id_focused == id: glColor4f(1., 1., 1., 0.95)346 elif self.id_active == id: glColor4f(1., 0.3, 0.3, 0.95)347 elif self.id_hot == id: glColor4f(1., 0.7, 0.7, 0.95)348 else: glColor4f(0.85, 0.85, .85, 0.9)349350 glDisable(GL_TEXTURE_2D)351 self._draw_filled_rect(x, y, w, h)352353 glColor4f(0.4, 0.4, 0.4, 1.)354 self._draw_rect(x, y, w, h)355 glEnable(GL_TEXTURE_2D)356 self.font.drawml(ret_new_text, x + 5, y + h / 2., z = self.z, fgcolor = fgcolor, bgcolor = (0., 0., 0., 0.))357358 # draw the blinking cursor359 if self.id_focused == id and int(time.time() * 4) % 2:360 glColor4f(0.4, 0.4, 0.4, 1.)361 glDisable(GL_TEXTURE_2D)362 self._draw_filled_rect(x + 5 + self.font.width(ret_new_text), y+3, 1, h-6)363364 return ret_changed, ret_new_text365366 def event(self, event):367 # http://wiki.libsdl.org/SDL_Scancode368 if event.type == SDL_KEYDOWN:369 if self.id_focused:370 #llog.info("keysym %s scancode %s", event.key.keysym.sym, event.key.keysym.scancode)371 sym = event.key.keysym.sym372 # is ascii printable chars?373 # append (character, keycode) if character is ascii-printable. else character is None374 self.keyqueue.append((chr(sym) if 0x20 <= sym <= 0x7e else None, event.key.keysym.scancode))375 #if event.key.keysym.scancode == SDL_SCANCODE_ESCAPE:376377 def _mouse_is_inside(self, x, y, w, h):378 if x <= self.mouse_x and y <= self.mouse_y and \379 x + w > self.mouse_x and y + h > self.mouse_y:380 return True381382 return False383384 def set_mouse_pos(self, x, y):385 self.mouse_x, self.mouse_y = x, y386387 def set_mouse_button(self, leftmousebutton):388 """ boolean """389 # if left button was pressed390 if not self.mouseleftclick and leftmousebutton:391 self.mouseleftclickpos = (self.mouse_x, self.mouse_y)392 self.mouseleftclick = True393 # if left button was released394 elif self.mouseleftclickpos and not leftmousebutton:395 self.mouseleftclicked = True396397 self.mousedown = leftmousebutton398399 def tick(self):400 """401 call this AFTER done using nugui for the frame.402 """403 self.id_hot = 0404 if not self.mousedown: self.id_active = 0405 #else: self.id_active = 0 # -1406 self.mouseleftclick = False407 self.mouseleftclicked = False408409 def _draw_filled_rect(self, x, y, w, h):410 z = self.z411 glBegin(GL_QUADS)412 glVertex3f(x, y, z)413 glVertex3f(x + w, y, z)414 glVertex3f(x + w, y + h, z)415 glVertex3f(x, y + h, z)416 glEnd()417418 def _draw_rect(self, x, y, w, h):419 xl = .5 + x420 xr = w - 0.5 + x421 yb = h - 0.5 + y422 yt = .5 + y423 z = self.z424425 #xl = x426 #xr = w + x - 1.427 #yb = h + y - 1.428 #yt = y429430 glBegin(GL_LINE_LOOP)431 glVertex3f(xl, yt, z)432 glVertex3f(xr, yt, z)433 glVertex3f(xr, yb, z)434 glVertex3f(xl, yb, z) ...

Full Screen

Full Screen

dealequip.py

Source:dealequip.py Github

copy

Full Screen

1import os2import sys3sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../'))4import logging5logger = logging.getLogger(__name__)6from superai.equip import OpenBagScene, CloseBagScene7from superai.vkcode import VK_CODE8from superai.common import InitLog, GameWindowToTop, KongjianSleep, RanSleep9from superai.gameapi import GameApiInit, FlushPid, GetBagEquipObj, BODYPOS, Clear, GetEquipObj10from superai.flannfind import Picture, GetImgDir11from superai.location import Location12from superai.anjian import aj13fenjieGelanzhisen = Picture(GetImgDir() + "fenjie_gelanzhisen.png")14fenjieTiankongzhicheng = Picture(GetImgDir() + "fenjie_tiankonghzicheng.png")15fenjieTianzhuijushou = Picture(GetImgDir() + "fenjieTianzhuijushou.png")16fenjieButton = Picture(GetImgDir() + "fenjie_button.png")17fenjiexiulijiScene = Picture(GetImgDir() + "fenjiexiuliji_scene.png")18fenjieConfirm = Picture(GetImgDir() + "fenjie_confirm.png")19fenjieAfaliya = Picture(GetImgDir() + "fenjieAfaliya.png")20fenjieNuoyipeila = Picture(GetImgDir() + "fenjie_nuoyipeila.png")21fenjieXueshan = Picture(GetImgDir() + "fenjie_xuieshan.png")22fenjieNuosimaer = Picture(GetImgDir() + "fenjie_nuosimaer.png")23fenjieyanuofasenlin = Picture(GetImgDir() + "fenjie_yanuofasenlin.png")24fenjieeyunzhicheng = Picture(GetImgDir() + "fenjie_eyunzhicheng.png")25fenjieniliupubu = Picture(GetImgDir() + "fenjie_niliupubu.png")26fenjiegente = Picture(GetImgDir() + "fenjie_gente.png")27fenjiexuankonghaigang = Picture(GetImgDir() + "fenjie_xuankonghaigang.png")28sellButton = Picture(GetImgDir() + "sellbt.png")29bagScene = Picture(GetImgDir() + "bagscene.png")30repairButton = Picture(GetImgDir() + "repair.png")31querenbtn = Picture(GetImgDir() + "querenbtn.png")32class DealEquip:33 def __init__(self):34 pass35 # 背包下标到相对位置36 def BagIdxToPos(self, idx, bagpos):37 firstpos = (bagpos[0] - 100, bagpos[1] + 220)38 cellw, cellh = 30, 3039 cellx, celly = idx % 8, idx // 840 pos = (firstpos[0] + cellw * cellx, firstpos[1] + cellh * celly)41 return pos42 # 获取到分解机位置43 def GetFenjieJiPos(self):44 pos = None45 location = Location()46 lo = location.GetFenjieLocation()47 if lo == "格兰之森":48 pos = fenjieGelanzhisen.Pos()49 if lo == "雪山":50 pos = fenjieXueshan.Pos()51 elif lo == "天空之城":52 pos = fenjieTiankongzhicheng.Pos()53 elif lo == "天锥巨兽":54 pos = fenjieTianzhuijushou.Pos()55 elif lo == "诺斯玛尔":56 pos = fenjieNuosimaer.Pos()57 elif lo == "阿法利亚":58 pos = fenjieAfaliya.Pos()59 elif lo == "诺伊佩拉":60 pos = fenjieNuoyipeila.Pos()61 elif lo == "亚诺法森林":62 pos = fenjieyanuofasenlin.Pos()63 elif lo == "厄运之城":64 pos = fenjieeyunzhicheng.Pos()65 elif lo == "逆流瀑布":66 pos = fenjieniliupubu.Pos()67 elif lo == "根特":68 pos = fenjiegente.Pos()69 elif lo == "悬空海港":70 pos = fenjiexuankonghaigang.Pos()71 return pos72 # 分解73 def FenjieAll(self):74 Clear()75 logger.info("分解所有")76 pos = self.GetFenjieJiPos()77 if pos is None or pos == (0, 0):78 return79 aj().MouseMoveTo(pos[0], pos[1]), KongjianSleep()80 aj().MouseLeftClick(), KongjianSleep()81 aj().MouseMoveR(56, 54), KongjianSleep()82 aj().MouseLeftClick(), KongjianSleep()83 # 分解按钮84 fenjiebt = fenjieButton.Pos()85 aj().MouseMoveTo(fenjiebt[0], fenjiebt[1]), KongjianSleep()86 # 检查 "稀有" "勇者" "包含我的职业装备" 是否勾选87 xiyoucheck = (Picture(GetImgDir() + "checked.png", fenjiebt[0] + 67, fenjiebt[1] + 47, 12, 12),88 (fenjiebt[0] + 67 + 6, fenjiebt[1] + 47 + 6))89 yongzhecheck = (Picture(GetImgDir() + "checked.png", fenjiebt[0] + 67, fenjiebt[1] + 61, 12, 12),90 (fenjiebt[0] + 67 + 6, fenjiebt[1] + 61 + 6))91 zhiyecheck = (Picture(GetImgDir() + "checked.png", fenjiebt[0] + 67, fenjiebt[1] + 80, 12, 12),92 (fenjiebt[0] + 67 + 6, fenjiebt[1] + 80 + 6))93 checks = [xiyoucheck, yongzhecheck, zhiyecheck]94 for v in checks:95 if not v[0].Match():96 aj().MouseMoveTo((v[1])[0], (v[1])[1]), KongjianSleep()97 aj().MouseLeftClick(), KongjianSleep()98 aj().MouseMoveTo(fenjiebt[0], fenjiebt[1]), KongjianSleep()99 # 分解按钮100 aj().MouseMoveTo(fenjiebt[0], fenjiebt[1]), KongjianSleep()101 aj().MouseLeftClick(), KongjianSleep()102 # 确认103 pos = fenjieConfirm.Pos()104 aj().MouseMoveTo(pos[0], pos[1]), KongjianSleep()105 aj().MouseLeftClick(), RanSleep(3.0)106 # 卖所有装备107 def SellAll(self):108 Clear()109 logger.info("出售所有")110 pos = self.GetFenjieJiPos()111 if pos is None or pos == (0, 0):112 return113 aj().MouseMoveTo(pos[0], pos[1]), KongjianSleep()114 aj().MouseLeftClick(), KongjianSleep()115 aj().MouseMoveR(56, 32), KongjianSleep()116 aj().MouseLeftClick(), KongjianSleep()117 # 出售按钮118 sellbtn = sellButton.Pos()119 aj().MouseMoveTo(sellbtn[0], sellbtn[1]), KongjianSleep()120 aj().MouseLeftClick(), KongjianSleep()121 bagpos = bagScene.Pos()122 equips = GetBagEquipObj()123 for v in equips:124 pos = self.BagIdxToPos(v.idx - 9, bagpos)125 aj().MouseMoveTo(pos[0], pos[1]), KongjianSleep()126 aj().MouseLeftClick(), KongjianSleep()127 aj().MouseLeftClick(), KongjianSleep()128 self.CloseSell()129 # 丢弃所有物品130 def DiscardAll(self):131 Clear()132 logger.info("丢弃所有")133 OpenBagScene()134 bagpos = bagScene.Pos()135 equips = GetBagEquipObj()136 for v in equips:137 pos = self.BagIdxToPos(v.idx - 9, bagpos)138 aj().MouseMoveTo(pos[0], pos[1]), KongjianSleep()139 aj().MouseLeftDown(), KongjianSleep()140 aj().MouseMoveTo(83, 129), KongjianSleep()141 aj().MouseLeftUp(), KongjianSleep()142 aj().MouseMoveR(100, 100), KongjianSleep()143 pos = querenbtn.Pos()144 aj().MouseMoveTo(pos[0], pos[1])145 aj().MouseLeftClick(), KongjianSleep()146 CloseBagScene()147 # 修理 (身上5件 + 武器)148 def RepairAll(self):149 Clear()150 logger.info("修理所有")151 pos = self.GetFenjieJiPos()152 if pos is None or pos == (0, 0):153 return154 aj().MouseMoveTo(pos[0], pos[1]), KongjianSleep()155 aj().MouseLeftClick(), KongjianSleep()156 aj().MouseMoveR(56, 32), KongjianSleep()157 aj().MouseLeftClick(), KongjianSleep()158 # 修理按钮159 repairbtn = repairButton.Pos()160 aj().MouseMoveTo(repairbtn[0], repairbtn[1]), KongjianSleep()161 aj().MouseLeftClick(), KongjianSleep()162 aj().MouseLeftClick(), KongjianSleep()163 # 是否需要被修理164 def NeedRepair(self):165 equips = GetEquipObj()166 for v in equips:167 if v.bodypos in BODYPOS or v.bodypos == 12:168 if v.maxnaijiu > 0.0 and v.curnaijiu / v.maxnaijiu < 0.25:169 return True170 return False171 # 关闭分解机172 def CloseFenjie(self):173 while fenjiexiulijiScene.Match():174 logger.info("关闭分解机")175 aj().PressKey(VK_CODE["esc"]), KongjianSleep()176 # 关闭卖物177 def CloseSell(self):178 while sellButton.Match():179 logger.info("关闭分解机")180 aj().PressKey(VK_CODE["esc"]), KongjianSleep()181def main():182 # InitLog()183 # if not GameApiInit():184 # sys.exit()185 # FlushPid()186 # if not aj().Init():187 # sys.exit()188 # GameWindowToTop()189 #190 # dq = DealEquip()191 # print(dq.NeedRepair())192 pos = fenjiexuankonghaigang.Pos()193 print(pos)194if __name__ == '__main__':...

Full Screen

Full Screen

HSI_pixel_viewer.py

Source:HSI_pixel_viewer.py Github

copy

Full Screen

1import numpy as np2import matplotlib.pyplot as plt3from utils import open_file4import cv2 5from matplotlib import font_manager, rc6font_name = font_manager.FontProperties(fname="c:/Windows/Fonts/malgun.ttf").get_name()7rc('font', family=font_name)89abs_path = 'Datasets/20210201_HSI_datasets/'10dir_name = 'abalone_hairN/'11path = abs_path + dir_name1213im = cv2.imread(path+'image.png')14HSI_data = open_file(path+'data.hdr',path+'data')151617def MouseLeftClick(event, x, y, flags, param):18 # 왼쪽 마우스가 클릭되면 (x, y) 좌표를 저장한다.19 if event == cv2.EVENT_LBUTTONDOWN:20 points.append([y,x])21 22# plt.close()23# for _, point in enumerate(points):24# y, x = point25 pixel = HSI_data[y:y+1,x:x+1,:]26 pixel_squeezed = np.squeeze(pixel)27 plt.plot(bands, pixel_squeezed)28 2930 plt.draw()31# plt.show()32 33points = []34cv2.namedWindow("image")35cv2.setMouseCallback("image", MouseLeftClick)36bands = np.arange(0,372)3738#plt.figure()39plt.xlabel('밴드')40plt.ylabel('반사도')41plt.ylim(0,23000)42plt.grid()4344while True:45 cv2.imshow("image", im)46 key = cv2.waitKey(0)47 48 if key == ord('q'):49 break50 51 ...

Full Screen

Full Screen

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 pyatom 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