Find Similar Images in Candy Crush BOT
Now we are ready to go through the fire. We will use template matching for matching all similar candies and saving their coordinates into a list.
Now for this save all types of templates into different folders named with specific colors like red, green, etc.
Create a new folder named Candy Crush BOT ( or of your choice ) in this folder make some sub-folders
An example for violet template is : -
Now save templates of different colors in series like 1.png, 2.png, 3.png.
In CCB ( Candy Crush BOT ) folder create a new script file named "cb.py"
Run CC game in BS2 and open file in IDLE and paste the following code : -
Now for this save all types of templates into different folders named with specific colors like red, green, etc.
Create a new folder named Candy Crush BOT ( or of your choice ) in this folder make some sub-folders
- Image
- Data
- Red
- Yellow
- Green
- Blue
- Orange
- Violet
An example for violet template is : -
1.png |
In CCB ( Candy Crush BOT ) folder create a new script file named "cb.py"
Run CC game in BS2 and open file in IDLE and paste the following code : -
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import cv2,time,os,pyautogui import numpy as np from matplotlib import pyplot as plt time.sleep(3) im = pyautogui.screenshot('sc.png') img_rgb = cv2.imread('sc.png') img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) template = cv2.imread('Images/Violet/1.png',0) w, h = template.shape[::-1] res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED) threshold = 0.75 loc = np.where( res >= threshold) cords = [] for pt in zip(*loc[::-1]): if delf(pt[0],pt[1],cords) == "a": continue cords.append(str(pt[0])+" "+str(pt[1])) cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2) print pt[0],pt[1] cv2.imwrite('red-'+'res.png',img_rgb) |
We will start from 1st level so when Candies have loaded run above script and hide the console within 3 seconds as as you can see in line 5. Game screen should be at topmost.
After around 5 seconds open folder CCB and you will find an image named "red-res.png" open it and this should be like following image : -
Congo!!! We successfully done our first tutorial .
Stay tuned we will learn to matching 3 candies soon.
Keep liking and sharing
0 comments:
Post a Comment