Reputation: 95
I'm looking to label specific x,y coordinates in my image with letter values. I saw that OpenCV has a "putText" function, but that only allows me to overlay text on one of the corners of the image. I have x,y coordinates where I'd like to overlay the text.
Is there any way to do this through OpenCV and if not, how might I do this?
Edit: clarification that I'm trying to do this in C++.
Upvotes: 3
Views: 3110
Reputation: 6707
cv::Point pt(x,y); // pixel coordinates
cv::putText( img, my_string, pt, cv::FONT_HERSHEY_PLAIN, 2.0, cv::Scalar(blue,green,red);
The 5th argument is a scale value, adjust on your needs
The color values are in the range (0-255), for a CV_8UC3
image.
You have additional fonts here.
These are the only requested arguments but you have more if needed, see here.
Upvotes: 1
Reputation: 1516
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img,'OpenCV',(x,y), font, 4,(255,255,255),2,cv2.LINE_AA)
where font is the font and (x,y) is the coordinate of the text
C++: void putText(InputOutputArray img, const String& text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=LINE_8, bool bottomLeftOrigin=false )
Pass org the point cordinates of the text
Upvotes: 0