亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

python識別圍棋定位棋盤位置

瀏覽:4日期:2022-07-28 09:03:04
目錄效果圖思路分析源碼:定位棋盤位置

最近需要做一個圍棋識別的項目,首先要將棋盤位置定位出來,效果圖如下:

效果圖

原圖

python識別圍棋定位棋盤位置

中間處理效果

python識別圍棋定位棋盤位置

最終結果

python識別圍棋定位棋盤位置

思路分析

我們利用python opencv的相關函數進行操作實現,根據棋盤顏色的特征,尋找到相關特征,將棋盤區域摳出來。最好從原始圖像中將棋盤位置截取出來。

源碼:定位棋盤位置

from PIL import ImageGrabimport numpy as npimport cv2from glob import globimglist = sorted(glob('screen/*.jpg'))for i in imglist:# while 1: img = cv2.imread(i) image = img.copy() w,h,c = img.shape img2 = np.zeros((w,h,c), np.uint8) img3 = np.zeros((w,h,c), np.uint8) # img = ImageGrab.grab() #bbox specifies specific region (bbox= x,y,width,height *starts top-left)hsv=cv2.cvtColor(img,cv2.COLOR_BGR2HSV) lower = np.array([10,0,0]) upper = np.array([40,255,255]) mask = cv2.inRange(hsv,lower,upper) erodeim = cv2.erode(mask,None,iterations=2) # 腐蝕 dilateim = cv2.dilate(erodeim,None,iterations=2) img = cv2.bitwise_and(img,img,mask=dilateim) frame = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) ret, dst = cv2.threshold(frame, 100, 255, cv2.THRESH_BINARY) contours,hierarchy = cv2.findContours(dst, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) cv2.imshow('0',img) i = 0 maxarea = 0 nextarea = 0 maxint = 0 for c in contours:if cv2.contourArea(c)>maxarea: maxarea = cv2.contourArea(c) maxint = ii+=1 #多邊形擬合 epsilon = 0.02*cv2.arcLength(contours[maxint],True) if epsilon<1:continue#多邊形擬合 approx = cv2.approxPolyDP(contours[maxint],epsilon,True) [[x1,y1]] = approx[0] [[x2,y2]] = approx[2] checkerboard = image[y1:y2,x1:x2] cv2.imshow('1',checkerboard) cv2.waitKey(1000)cv2.destroyAllWindows()

帶保存圖像

from PIL import ImageGrabimport numpy as npimport cv2from glob import globimport osimglist = sorted(glob('screen/*.jpg'))a=0for i in imglist:# while 1: a=a+1 img = cv2.imread(i) image = img.copy() w,h,c = img.shape img2 = np.zeros((w,h,c), np.uint8) img3 = np.zeros((w,h,c), np.uint8) # img = ImageGrab.grab() #bbox specifies specific region (bbox= x,y,width,height *starts top-left)hsv=cv2.cvtColor(img,cv2.COLOR_BGR2HSV) lower = np.array([10,0,0]) upper = np.array([40,255,255]) mask = cv2.inRange(hsv,lower,upper) erodeim = cv2.erode(mask,None,iterations=2) # 腐蝕 dilateim = cv2.dilate(erodeim,None,iterations=2) img = cv2.bitwise_and(img,img,mask=dilateim) frame = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) ret, dst = cv2.threshold(frame, 100, 255, cv2.THRESH_BINARY) contours,hierarchy = cv2.findContours(dst, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # 保存圖片的地址 img_file_1 = './temp' # 確認上述地址是否存在 if not os.path.exists(img_file_1):os.mkdir(img_file_1) cv2.imshow('0',img) cv2.imwrite(img_file_1 + '/' + ’temp_%d.jpg’%a, img) i = 0 maxarea = 0 nextarea = 0 maxint = 0 for c in contours:if cv2.contourArea(c)>maxarea: maxarea = cv2.contourArea(c) maxint = ii+=1 #多邊形擬合 epsilon = 0.02*cv2.arcLength(contours[maxint],True) if epsilon<1:continue#多邊形擬合 approx = cv2.approxPolyDP(contours[maxint],epsilon,True) [[x1,y1]] = approx[0] [[x2,y2]] = approx[2] checkerboard = image[y1:y2,x1:x2] cv2.imshow('1',checkerboard) cv2.waitKey(1000) # 保存圖片的地址 img_file_2 = './checkerboard' # 確認上述地址是否存在 if not os.path.exists(img_file_2):os.mkdir(img_file_2) cv2.imwrite(img_file_2 + '/' + ’checkerboard_%d.jpg’%a, checkerboard)cv2.destroyAllWindows()

到此這篇關于python識別圍棋定位棋盤位置的文章就介紹到這了,更多相關python 圍棋定位棋盤位置內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 欧美一级aa天码毛片 | 亚洲精品色综合久久久 | 看黄色一级大片 | 黄色一级大片 | 久久久久国产一级毛片高清版 | 日韩第一页在线观看 | a国产 | 国产成人精视频在线观看免费 | 亚洲aⅴ久久久噜噜噜噜 | 日本一级级特黄特色大片 | 仑乱高清在线一级播放 | 婷婷激情狠狠综合五月 | 国产精品1区 2区 3区 | 美美女高清毛片视频黄的一免费 | 国产视频欧美 | 欧美日韩一区二区三区在线播放 | 黄色网址视频 | 国产乱熟肥女视频网站 | 国产大片中文字幕在线观看 | 午夜性激福利免费观看 | 日韩乱淫| 九一国产精品 | 尤物在线 | 亚洲一区二区中文字5566 | 国产精品久久现线拍久青草 | 国产一级精品高清一级毛片 | 88国产精品视频一区二区三区 | 日韩成人黄色片 | 织田真子中文字幕 | 亚洲欧美一区二区三区综合 | 在线观看成人免费 | 免费大片黄在线观看日本 | 男人影院在线观看 | 97视频免费播放观看在线视频 | 欧美色图自拍 | 大尺度做爰床戏呻吟免费观看91 | 国产51| 深夜福利视频在线看免费 | 中文字幕在线观看网站 | 国产剧情91| 国产成人精品午夜在线播放 |