如何使用给定的坐标和python opencv在图像中绘制点? [英] How to Draw a point in an image using given co-ordinate with python opencv?

查看:2203
本文介绍了如何使用给定的坐标和python opencv在图像中绘制点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张图像和一个坐标(X,Y).如何在此坐标上绘制点.我想使用Python OpenCV.

I have one image and one co-ordinate (X, Y). How to draw a point with this co-ordinate on the image. I want to use Python OpenCV.

推荐答案

我也在学习与OpenCV的Python绑定.这是一种方法:

I'm learning the Python bindings to OpenCV too. Here's one way:

#!/usr/local/bin/python3
import cv2
import numpy as np

w=40
h=20
# Make empty black image
image=np.zeros((h,w,3),np.uint8)

# Fill left half with yellow
image[:,0:int(w/2)]=(0,255,255)

# Fill right half with blue
image[:,int(w/2):w]=(255,0,0)

# Create a named colour
red = [0,0,255]

# Change one pixel
image[10,5]=red

# Save
cv2.imwrite("result.png",image)

这是结果-放大后可以看到它.

Here's the result - enlarged so you can see it.

这是非常简洁但有趣的答案:

Here's the very concise, but less fun, answer:

#!/usr/local/bin/python3
import cv2
import numpy as np

# Make empty black image
image=np.zeros((20,40,3),np.uint8)

# Make one pixel red
image[10,5]=[0,0,255]

# Save
cv2.imwrite("result.png",image)

这篇关于如何使用给定的坐标和python opencv在图像中绘制点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆