国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

OpenCV Python實(shí)現(xiàn)拼圖小游戲

瀏覽:8日期:2022-08-01 14:58:48

基于OpenCV實(shí)現(xiàn)拼圖版小游戲,供大家參考,具體內(nèi)容如下

效果展示

OpenCV Python實(shí)現(xiàn)拼圖小游戲

實(shí)現(xiàn)

思路

1.對(duì)圖像進(jìn)行分割,分割成m*n個(gè)子圖2.打亂子圖的順序3.將子圖重新組成一幅新的圖片并顯示4.添加鼠標(biāo)點(diǎn)擊響應(yīng)動(dòng)作,交換鼠標(biāo)依次點(diǎn)擊的兩張圖的位置5.每次交換后,判斷是否與原圖是否一致

python代碼

import cv2 as cvimport numpyimport randomimport mathsrc = cv.imread('D:CvPic1.jpg')print(src.shape)h = src.shape[0]w = src.shape[1]c = src.shape[2]row = 3col = 3offset_h = h/rowoffset_w = w/colfirstClick = FalseclickIdx = [0,0]tileList = []def calPicIdx(x, y): print(str(y)+' '+str(h/col)) i = y//(offset_h) print(str(y%offset_h)+' '+str(offset_w)) j = math.ceil((x%w)/offset_w) idx = i*row+j print('i:'+str(i)+' j:'+str(j)+' idx:'+str(idx)) return int(idx)def onMouse(event, x, y, flag ,params): if event==cv.EVENT_LBUTTONDOWN: print('left button down:'+str(x)+' '+str(y)) idx = calPicIdx(x, y) global firstClick firstClick = not firstClick print(firstClick) if firstClick: clickIdx[0] = idx else: clickIdx[1] = idx tileList[clickIdx[0]], tileList[clickIdx[1]] = tileList[clickIdx[1]], tileList[clickIdx[0]] for i in range(0, row): for j in range (0, col): dst[i*offset_h:(i+1)*offset_h-1, j*offset_w:(j+1)*offset_w-1] = tileList[i*row+j] cv.imshow('dst', dst) difference = cv.subtract(dst, src2) result = not numpy.any(difference) #if difference is all zeros it will return False print('result:'+str(result)) print(clickIdx)# --------------splite image into n*n tile--------------tile = numpy.zeros((offset_h-1, offset_w-1, c),numpy.uint8)for i in range(0, row): for j in range (0, col): tile = src[i*offset_h:(i+1)*offset_h-1, j*offset_w:(j+1)*offset_w-1] tileList.append(tile) # cv.imshow('tile', tile)# --------------ramdom the tiles--------------------print(len(tileList))for i in range(len(tileList)-1,0,-1): randomIdx = random.randint(0,i-1) print('swap:'+str(random.randint(0,i-1))+' '+str(i)) tileList[i], tileList[randomIdx] = tileList[randomIdx], tileList[i]# debug show every tile# for k,tile in enumerate(tileList):# cv.imshow('tile'+str(k), tile)dst = numpy.zeros((h, w, c), numpy.uint8)for i in range(0, row): for j in range (0, col): dst[i*offset_h:(i+1)*offset_h-1, j*offset_w:(j+1)*offset_w-1] = tileList[i*row+j]cv.namedWindow('dst')cv.setMouseCallback('dst', onMouse)cv.imshow('dst', dst)# -------------match the origin image and now--------------src2 = src.copy()for i in range(1, row): src2[i*offset_h-1:i*offset_h]= numpy.zeros((1,w,3), numpy.uint8) for j in range(1, col): src2[0:h,j*offset_w-1:j*offset_w]= numpy.zeros((h,1,3), numpy.uint8)# cv.imshow('src2', src2)cv.waitKey(0)

參考

90年代經(jīng)典“手游”—拼圖板小游戲Opencv實(shí)現(xiàn)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 欧美日韩在线播一区二区三区 | 美女又黄又免费的视频 | 亚洲成人视 | 熟女毛片| 国产三级做爰在线观看∵ | 中文一区在线 | 天堂av2017男人的天堂 | 久久91综合国产91久久精品 | 成年午夜性视频免费播放 | 久草视频在线播放 | 日本性色| 久久精品国产线看观看亚洲 | 成人午夜视频一区二区国语 | 国产精品18久久久久网站 | 国产永久高清免费动作片www | 欧美日本一二三区 | 国产极品精频在线观看 | 日产国产精品久久久久久 | 毛片免费观看网址 | 日韩欧美一及在线播放 | 7799国产精品久久久久99 | 一区二区三区亚洲 | 欧美专区一区二区三区 | 国产精品免费视频一区一 | 欧美性生交大片免费看 | 久久久久久色 | 午夜影院免费体验 | 久久两性视频 | 中文字幕二区 | 欧美日韩一区二区三区在线 | 7799国产精品久久久久99 | 亚洲国产精品专区 | 日本在线免费播放 | 欧美 自拍 | 国产性大片黄在线观看在线放 | 国产99久久精品 | 国产主播福利精品一区二区 | 色资源二区在线视频 | 亚洲成人黄色在线观看 | 国产精品资源手机在线播放 | 日本农村寡妇一级毛片 |