Draw arrows (vectors) with opencv / python

Created Python version from Draw Arrows with OpenCV.

def cvArrow(img, pt1, pt2, color, thickness=1, lineType=8, shift=0):
    cv2.line(img,pt1,pt2,color,thickness,lineType,shift)
    vx = pt2[0] - pt1[0]
    vy = pt2[1] - pt1[1]
    v  = math.sqrt(vx ** 2 + vy ** 2)
    ux = vx / v
    uy = vy / v
    #The width of the arrow
    w = 5
    h = 10
    ptl = (int(pt2[0] - uy*w - ux*h), int(pt2[1] + ux*w - uy*h))
    ptr = (int(pt2[0] + uy*w - ux*h), int(pt2[1] - ux*w - uy*h))
    #Draw the tip of the arrow
    cv2.line(img,pt2,ptl,color,thickness,lineType,shift)
    cv2.line(img,pt2,ptr,color,thickness,lineType,shift)

I'm blogging: http://weed.nagoya

Recommended Posts

Draw arrows (vectors) with opencv / python
Binarization with OpenCV / Python
"Apple processing" with OpenCV3 + Python3
Image editing with python OpenCV
Camera capture with Python + OpenCV
Draw netCDF file with python
[Python] Using OpenCV with Python (Basic)
Face detection with Python + OpenCV
Shining life with Python and OpenCV
[Python] Using OpenCV with Python (Image Filtering)
Neural network with OpenCV 3 and Python 3
[Python] Using OpenCV with Python (Image transformation)
[Python] Using OpenCV with Python (Edge Detection)
Easy Python + OpenCV programming with Canopy
Draw Koch curve with Python Turtle
Cut out face with Python + OpenCV
Face recognition with camera with opencv3 + python2.7
Load gif images with Python + OpenCV
Find image similarity with Python + OpenCV
Draw Lyapunov Fractal with Python, matplotlib
Graph Based Segmentation with Python + OpenCV
Draw shapes with OpenCV and PIL
Basic study of OpenCV with Python
Face detection with Python + OpenCV (rotation invariant)
Save video frame by frame with Python OpenCV
Draw Nozomi Sasaki in Excel with python
Capturing images with Pupil, python and OpenCV
I tried non-photorealistic rendering with Python + opencv
Image processing with Python & OpenCV [Tone Curve]
Image acquisition from camera with Python + OpenCV
[python, openCV] base64 Face recognition with images
Create miscellaneous Photoshop videos with Python + OpenCV ③ Create miscellaneous Photoshop videos
[Python] Read images with OpenCV (for beginners)
Light image processing with Python x OpenCV
Smoothing edge-saved with python + OpenCV (BilateralFilter, NLMeansFilter)
FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
python starts with ()
OpenCV Samples (Python)
Bingo with python
Zundokokiyoshi with python
[Note] openCV + python
Excel with Python
Microcomputer with Python
Cast with python
Hello World and face detection with OpenCV 4.3 + Python
I tried "smoothing" the image with Python + OpenCV
Performance comparison of face detector with Python + OpenCV
I tried "differentiating" the image with Python + OpenCV
Edge extraction with python + OpenCV (Sobel filter, Laplacian filter)
Try to draw a life curve with python
How to crop an image with Python + OpenCV
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
[Python] Draw a Mickey Mouse with Turtle [Beginner]
Make OpenCV3 available from python3 installed with pyenv