寻找像素点

第一个代码块:图片太大了,缩减一般
第二个代码块:原图大小

import cv2

# 读取图片,并调整大小   图片地址自己整理
img = cv2.imread(r'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
# 定义缩放比例,例如缩小到原来的一半
scale_percent = 50  # 50% of original size
width = int(img.shape[1] * scale_percent / 100)
height = int(img.shape[0] * scale_percent / 100)
dim = (width, height)

# 使用cv2.resize()函数调整图片大小
resized_img = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)

# 鼠标点击事件函数
def on_EVENT_LBUTTONDOWN(event, x, y, flags, param):
    global img
    if event == cv2.EVENT_LBUTTONDOWN:
        xy = "%d,%d" % (x, y)
        print(x, y)
        # 画圆和文字时使用调整大小后的图片
        cv2.circle(resized_img, (x, y), 2, (0, 0, 255))
        cv2.putText(resized_img, xy, (x, y), cv2.FONT_HERSHEY_PLAIN, 1.0, (0, 0, 255))

# 创建窗口并设置鼠标回调
cv2.namedWindow("image")
cv2.setMouseCallback("image", on_EVENT_LBUTTONDOWN)

# 显示调整大小后的图片
while (1):
    cv2.imshow("image", resized_img)  # 显示调整大小后的图片
    key = cv2.waitKey(5) & 0xFF
    if key == ord('q'):
        break

cv2.destroyAllWindows()
import cv2

img = cv2.imread(r'xxxxxxxxxxxxxxxxxxxxxxxxx')


def on_EVENT_LBUTTONDOWN(event, x, y, flags, param):
    if event == cv2.EVENT_LBUTTONDOWN:
        xy = "%d,%d" % (x, y)
        print(x, y)
        cv2.circle(img, (x, y), 2, (0, 0, 255))
        cv2.putText(img, xy, (x, y), cv2.FONT_HERSHEY_PLAIN, 1.0, (0, 0, 255))
        cv2.imshow("image", img)


cv2.namedWindow("image")
cv2.setMouseCallback("image", on_EVENT_LBUTTONDOWN)
while (1):
    cv2.imshow("image", img)
    key = cv2.waitKey(5) & 0xFF
    if key == ord('q'):
        break
cv2.destroyAllWindows()```

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值