我有一个图像,我需要在其中检测X行内的符号。
图片:
正如您在上图中所看到的,X线内有一个符号。我想知道符号的 X 和 Y 坐标。有没有办法在这张图片中找到这个符号,或者它很小?
import cv2
import numpy as np
def calculateCenterSpot(results):
startX, endX = results[0][0], results[0][2]
startY, endY = results[0][1], results[0][3]
centerSpotX = (endX - startX) / 2 + startX
centerSpotY = (endY - startY) / 2 + startY
return [centerSpotX, centerSpotY]
img = cv2.imread('crop_1.png')
res2 = img.copy()
cords = [[1278, 704, 1760, 1090]]
center = calculateCenterSpot(cords)
cv2.circle(img, (int(center[0]), int(center[1])), 1, (0,0,255), 30)
cv2.line(img, (int(center[0]), 0), (int(center[0]), img.shape[0]), (0,255,0), 10)
cv2.line(img, (0, …Run Code Online (Sandbox Code Playgroud) 我正在做一个只是为了好玩的项目,我的目标是玩在线扑克并让程序识别桌上的牌。我正在使用带有 python 的 OpenCV 来隔离卡片所在的区域。我已经能够拍摄该区域的图像,对其进行灰度和阈值处理,并在卡片边缘绘制轮廓。我现在被困在如何前进的问题上。
到目前为止,这是我的代码:
import cv2
from PIL import ImageGrab
import numpy as np
def processed(image):
grayscaled = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresholded = cv2.Canny(grayscaled, threshold1 = 200, threshold2 = 200)
return thresholded
def drawcard1():
screen = ImageGrab.grab(bbox = (770,300,850,400))
processed_img = processed(np.array(screen))
outside_contour, dummy = cv2.findContours(processed_img.copy(), 0,2)
colored = cv2.cvtColor(processed_img, cv2.COLOR_GRAY2BGR)
cv2.drawContours(colored, outside_contour, 0, (0,255,0),2)
cv2.imshow('resized_card', colored)
while True:
drawcard1()
if cv2.waitKey(25) & 0xFF == ord('w'):
cv2.destroyAllWindows()
break
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止的结果:

我需要能够获取轮廓的内部,并删除它外部的任何东西。然后生成的图像应该只是卡片,我需要将其缩放到 49x68 像素。一旦我能做到这一点,我的计划是获得等级和西装的轮廓,并用白色像素填充它,然后我会将其与一组图像进行比较以确定最适合的。
我对 OpenCV 和图像处理非常陌生,但我发现这些东西非常吸引人!我已经能够通过谷歌走到这一步,但这次我找不到任何东西。
这是我现在用来替换游戏的图像:

这是我将用来比较桌卡的图像之一:

我有数百张珠宝产品的图片。其中一些带有“畅销书”标签。标签的位置因图像而异。我想遍历所有图像,如果图像具有此标签,则将其删除。结果图像将在移除对象的像素上渲染背景。
带有标签/贴纸/对象的图像示例:

要移除的标签/贴纸/对象:

import numpy as np
import cv2 as cv
img = plt.imread('./images/001.jpg')
sticker = plt.imread('./images/tag.png',1)
diff_im = cv2.absdiff(img, sticker)
Run Code Online (Sandbox Code Playgroud)
我希望得到的图像是这样的:
