diff --git a/_includes/cropimg.html b/_includes/cropimg.html index 1b25753e..3ff4839b 100644 --- a/_includes/cropimg.html +++ b/_includes/cropimg.html @@ -4,7 +4,6 @@
from matplotlib import pyplot as plt
-
from arknights_mower.utils.image import cropimg, loadimg
import cv2
+from matplotlib import pyplot as plt
+from arknights_mower.utils.image import loadimg
+from arknights_mower.utils.matcher import ORB, flann
+
res = loadimg("/home/zhao/Documents/hot_update/hortus/terminal.jpg", True)
+plt.imshow(res, cmap="gray", vmin=0, vmax=255)
+plt.show()
+kp1, des1 = ORB.detectAndCompute(res, None)
+img = cv2.drawKeypoints(res, kp1, None, (0, 255, 0), flags=0)
+plt.imshow(img)
+plt.show()
+
sc = loadimg("/home/zhao/Documents/mower-profile/screenshot/501/20240705031952.png", True)
+plt.imshow(sc, cmap="gray", vmin=0, vmax=255)
+plt.show()
+kp2, des2 = ORB.detectAndCompute(sc, None)
+img = cv2.drawKeypoints(sc, kp2, None, (0, 255, 0), flags=0)
+plt.imshow(img)
+plt.show()
+
matches = flann.knnMatch(des1, des2, k=2)
+GOOD_DISTANCE_LIMIT = 0.7
+good = []
+for pair in matches:
+ if (len_pair := len(pair)) == 2:
+ x, y = pair
+ if x.distance < GOOD_DISTANCE_LIMIT * y.distance:
+ good.append(x)
+ elif len_pair == 1:
+ good.append(pair[0])
+good = sorted(good, key=lambda x: x.distance)
+debug_img = cv2.drawMatches(
+ res,
+ kp1,
+ sc,
+ kp2,
+ good[:50],
+ None,
+ (0, 255, 0),
+ flags=cv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS,
+)
+plt.imshow(debug_img)
+plt.show()
+
debug_img = cv2.cvtColor(sc, cv2.COLOR_GRAY2RGB)
+center = list(map(int, kp2[good[0].trainIdx].pt))
+print(center)
+cv2.circle(debug_img, center, 20, (0, 255, 0), 5)
+plt.imshow(debug_img)
+plt.show()
+
sc = loadimg("/home/zhao/Documents/mower-profile/screenshot/501/20240705071219.png", True)
+plt.imshow(sc, cmap="gray", vmin=0, vmax=255)
+plt.show()
+kp2, des2 = ORB.detectAndCompute(sc, None)
+img = cv2.drawKeypoints(sc, kp2, None, (0, 255, 0), flags=0)
+plt.imshow(img)
+plt.show()
+
matches = flann.knnMatch(des1, des2, k=2)
+GOOD_DISTANCE_LIMIT = 0.7
+good = []
+for pair in matches:
+ if (len_pair := len(pair)) == 2:
+ x, y = pair
+ if x.distance < GOOD_DISTANCE_LIMIT * y.distance:
+ good.append(x)
+ elif len_pair == 1:
+ good.append(pair[0])
+good = sorted(good, key=lambda x: x.distance)
+debug_img = cv2.drawMatches(
+ res,
+ kp1,
+ sc,
+ kp2,
+ good[:50],
+ None,
+ (0, 255, 0),
+ flags=cv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS,
+)
+plt.imshow(debug_img)
+plt.show()
+
debug_img = cv2.cvtColor(sc, cv2.COLOR_GRAY2RGB)
+center = list(map(int, kp2[good[0].trainIdx].pt))
+print(center)
+cv2.circle(debug_img, center, 20, (0, 255, 0), 5)
+plt.imshow(debug_img)
+plt.show()
+
import cv2
+from matplotlib import pyplot as plt
+from arknights_mower.utils.image import loadimg
+from arknights_mower.utils.matcher import ORB
+
sc = loadimg("/home/zhao/Documents/mower-profile/screenshot/201/20240713031749.png", True)
+plt.imshow(sc, cmap="gray", vmin=0, vmax=255)
+plt.show()
+
kp, des = ORB.detectAndCompute(sc, None)
+print(len(kp))
+img = cv2.drawKeypoints(sc, kp, None, (0, 255, 0), flags=0)
+plt.imshow(img)
+plt.show()
+
sc = loadimg("/home/zhao/Documents/mower-profile/screenshot/103/20240713152407.png", True)
+plt.imshow(sc, cmap="gray", vmin=0, vmax=255)
+plt.show()
+
kp, des = ORB.detectAndCompute(sc, None)
+print(len(kp))
+img = cv2.drawKeypoints(sc, kp, None, (0, 255, 0), flags=0)
+plt.imshow(img)
+plt.show()
+
from matplotlib import pyplot as plt
-
from arknights_mower.utils.image import loadimg, loadres
from matplotlib import pyplot as plt
-
from arknights_mower.utils.image import loadimg, thres2