好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > python識別圍棋定位棋盤位置

python識別圍棋定位棋盤位置

熱門標簽:西青語音電銷機器人哪家好 無錫智能外呼系統好用嗎 成都呼叫中心外呼系統哪家強 電梯新時達系統外呼顯示e 百應電話機器人總部 宿州電話機器人哪家好 地圖標注與注銷 南昌地圖標注 旅游廁所地圖標注怎么弄

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

效果圖

原圖

中間處理效果

最終結果

思路分析

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

源碼:定位棋盤位置

from PIL import ImageGrab
import numpy as np
import cv2
from glob import glob

imglist = 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 = i
        i+=1

    #多邊形擬合
    epsilon = 0.02*cv2.arcLength(contours[maxint],True)
    if epsilon1:
        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 ImageGrab
import numpy as np
import cv2
from glob import glob
import os

imglist = sorted(glob("screen/*.jpg"))
a=0
for 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 = i
        i+=1

    #多邊形擬合
    epsilon = 0.02*cv2.arcLength(contours[maxint],True)
    if epsilon1:
        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定位棋子位置及識別棋子顏色

標簽:許昌 濰坊 七臺河 雅安 西安 贛州 渭南 辛集

巨人網絡通訊聲明:本文標題《python識別圍棋定位棋盤位置》,本文關鍵詞  python,識別,圍棋,定位,棋盤,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《python識別圍棋定位棋盤位置》相關的同類信息!
  • 本頁收集關于python識別圍棋定位棋盤位置的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 麻豆精品国产熟妇aⅴ一区| 24小时免费看b站| 精品欧美一区二区久久久伦| 艳妇的名器| 91精品人妖一区二区三区四区 | mu子媾交全文阅读| 日韩欧美中国av| 大黄一级片| 色综合久久久久综合一小说| 69色综合| 九九久久精品国产| 国产精品沙发午睡系列| 亚洲乱码在线播放| 黄色小说在线读| 91嫩草国产在线观看免费| 天堂va亚洲va国产va欧美| 和搜子同居的日子2bd中文在线视频 | 污污视频免费观看| 白洁少妇在办公室被躁| 国产精品喷潮抽搐无| 无码熟妇人妻AV又大又粗| 黑人粗暴亚裔videos| 色播欧美| 乡下野战好大好硬好爽| 熟妇人妻精品一区二区三区视频| 爽?好紧?别夹?喷水在线观看| 两性动态图片o| 老熟九色91popny| 成年片色大黄全免费网址| 韩国精品一区视频在线播放| 精品成人久久| 爽?好?舒服?短裙视频| 美女又爽?又黄?偷拍app| 日本全裸美女| 精品国产专区91在线app| 精品国产高清久久久久久小说| GOGO全球高清大尺度无吗亚| 亚洲91在线视频| 美女搞逼视频| 同桌啊哈轻点嗯在上课呢| 2020毛片|