How to Draw a point in an image using given co-ordinate with python opencv?
You can use cv2.circle() function opencv module:
image = cv.circle(image, centerOfCircle, radius, color, thickness)
Keep radius as 0 for plotting a single point and thickness as a negative number for filled circle
import cv2image = cv2.circle(image, (x,y), radius=0, color=(0, 0, 255), thickness=-1)
I'm learning the Python bindings to OpenCV too. Here's one way:
#!/usr/local/bin/python3import cv2import numpy as npw=40h=20# Make empty black imageimage=np.zeros((h,w,3),np.uint8)# Fill left half with yellowimage[:,0:int(w/2)]=(0,255,255)# Fill right half with blueimage[:,int(w/2):w]=(255,0,0)# Create a named colourred = [0,0,255]# Change one pixelimage[10,5]=red# Savecv2.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/python3import cv2import numpy as np# Make empty black imageimage=np.zeros((20,40,3),np.uint8)# Make one pixel redimage[10,5]=[0,0,255]# Savecv2.imwrite("result.png",image)