How to draw lines on an image in OpenCV?


Rahul:

If I have polar coordinates of a line, how can I draw it on an image in OpenCV and python?

LineThe function takes 2 points, but only draws line segments. I want to draw a line from one edge of an image to the other.

Robert Caspary:

Just count 2 points. Opencv's Line can use (-10, -10) to represent a point.

import cv2  # python-opencv
import numpy as np

width, height = 800, 600
x1, y1 = 0, 0
x2, y2 = 200, 400
image = np.ones((height, width)) * 255

line_thickness = 2
cv2.line(image, (x1, y1), (x2, y2), (0, 255, 0), thickness=line_thickness)

http://docs.opencv.org/2.4/modules/core/doc/drawing_functions.html#cv2.line

Related


How to draw lines on an image in OpenCV?

Rahul: If I have polar coordinates of a line, how can I draw it on an image in OpenCV and python? LineThe function takes 2 points, but only draws line segments. I want to draw a line from one edge of an image to the other. Robert Caspary: Just count 2 points.

How to draw lines on an image in OpenCV?

Rahul: If I have polar coordinates of a line, how can I draw it on an image in OpenCV and python? LineThe function takes 2 points, but only draws line segments. I want to draw a line from one edge of an image to the other. Robert Caspary: Just count 2 points.

How to find and draw the outer lines of an image in OpenCV?

Mr Programmer As i process the image(BEFORE) then i need its outer border and draw red line in openCV android (like AFTER image), If anyone knows about it, please let me know about advanced tanks. Costantino Grana This is a classic application of cv::findConto

How to find and draw the outer lines of an image in OpenCV?

Mr Programmer As i process the image(BEFORE) then i need its outer border and draw red line in openCV android (like AFTER image), If anyone knows about it, please let me know about advanced tanks. Costantino Grana This is a classic application of cv::findConto

draw lines and distances on image opencv python

user 300058 I'm having a problem with this: I can't draw a line on an image with a certain color, nor can I find out the distance to the place. Help make it look like the image below: my code: import cv2 import numpy as np from PIL import ImageGrab whil

How to draw perfect lines in python using opencv

Trojan War I am trying to draw perfect lines using mouse events by clicking and dragging the mouse. The problem is that multiple lines are printed when plotting. Here is the code I've been testing. import cv2 import numpy as np drawing = False x1,y1 = -1,-1

How to draw lines between points in OpenCV?

Open V I have a set of tuples: a = [(375, 193) (364, 113) (277, 20) (271, 16) (52, 106) (133, 266) (289, 296) (372, 282)] How to draw lines between points in OpenCV? Here is my code that doesn't work: for index, item in enumerate(a): print (item[index])

How to draw lines on OpenCV Camera Preview?

McMad I am using OpenCV camera preview. I want to draw a rectangle on live preview. I've tried to override the ondraw method but I can't see a line. please help. package com.example.easymeasure; import org.opencv.android.JavaCameraView; import android.conten

How to draw transparent lines on an image using PIL?

Retric Here is what I get: draw.line([(x1,y1),(x2,y2)],fill = (255, 255, 255)) The result is a white line, but I want a transparent line, what should I do? Kay Patel As far as I know, the line function takes RGB or RGBA values. try: draw.line([(x1,y1),(x2,y2)

How to draw lines on an image on a tkinter window?

smoked The program reads the image located at C:/Square.png and draws lines on it. Also defines the plot title. I want to display the whole image in a tkinter window. what should I do? Here is the image. The name has to be changed and we can run the code. http

How to draw lines on an image using matplotlib?

KhoaLearnToCode I'm having a problem here when trying to draw multiple lines on an image. So, here is my code: fig=plt.figure() final = cv2.imread('frame9.jpg') for p in polar: plt.plot([0,1],[p[0],p[0]],c='red') plt.imshow(final,cmap=plt.cm.gray) plt.show

How to draw transparent lines on an image using PIL?

Retric Here is what I get: draw.line([(x1,y1),(x2,y2)],fill = (255, 255, 255)) The result is a white line, but I want a transparent line, what should I do? Kay Patel As far as I know, the line function takes RGB or RGBA values. try: draw.line([(x1,y1),(x2,y2)

How to draw transparent lines on an image using PIL?

Retric Here is what I get: draw.line([(x1,y1),(x2,y2)],fill = (255, 255, 255)) The result is a white line, but I want a transparent line, what should I do? Kay Patel As far as I know, the line function takes RGB or RGBA values. try: draw.line([(x1,y1),(x2,y2)

How to draw transparent lines on an image using PIL?

Retric Here is what I get: draw.line([(x1,y1),(x2,y2)],fill = (255, 255, 255)) The result is a white line, but I want a transparent line, what should I do? Kay Patel As far as I know, the line function takes RGB or RGBA values. try: draw.line([(x1,y1),(x2,y2)

How to draw lines on an image on a tkinter window?

smoked The program reads the image located at C:/Square.png and draws lines on it. Also defines the plot title. I want to display the whole image in a tkinter window. what should I do? Here is the image. The name has to be changed and we can run the code. http

How to draw lines on an image using matplotlib?

KhoaLearnToCode I'm having a problem here when trying to draw multiple lines on an image. So, here is my code: fig=plt.figure() final = cv2.imread('frame9.jpg') for p in polar: plt.plot([0,1],[p[0],p[0]],c='red') plt.imshow(final,cmap=plt.cm.gray) plt.show

How to draw curved and straight lines in one image?

stack I'm trying to draw a rectangle that is basically a circle, with a square on one end. Kind of like a battery. I have some limitations, basically this can only be done with a single paint object and should be able to support strokes. Here is my code so far

How to draw lines on an image using matplotlib?

KhoaLearnToCode I'm having a problem here when trying to draw multiple lines on an image. So, here is my code: fig=plt.figure() final = cv2.imread('frame9.jpg') for p in polar: plt.plot([0,1],[p[0],p[0]],c='red') plt.imshow(final,cmap=plt.cm.gray) plt.show

How to draw lines on an image on a tkinter window?

smoked The program reads the image located at C:/Square.png and draws lines on it. Also defines the plot title. I want to display the whole image in a tkinter window. what should I do? Here is the image. The name has to be changed and we can run the code. http

How to draw transparent lines on an image using PIL?

Retric Here is what I get: draw.line([(x1,y1),(x2,y2)],fill = (255, 255, 255)) The result is a white line, but I want a transparent line, what should I do? Kay Patel As far as I know, the line function takes RGB or RGBA values. try: draw.line([(x1,y1),(x2,y2)

How to draw transparent lines on an image using PIL?

Retric Here is what I get: draw.line([(x1,y1),(x2,y2)],fill = (255, 255, 255)) The result is a white line, but I want a transparent line, what should I do? Kay Patel As far as I know, the line function takes RGB or RGBA values. try: draw.line([(x1,y1),(x2,y2)

How to draw lines on an image on a tkinter window?

smoked The program reads the image located at C:/Square.png and draws lines on it. Also defines the plot title. I want to display the whole image in a tkinter window. what should I do? Here is the image. The name has to be changed and we can run the code. http

How to draw lines on an image using matplotlib?

KhoaLearnToCode I'm having a problem here when trying to draw multiple lines on an image. So, here is my code: fig=plt.figure() final = cv2.imread('frame9.jpg') for p in polar: plt.plot([0,1],[p[0],p[0]],c='red') plt.imshow(final,cmap=plt.cm.gray) plt.show

How to draw lines on an image using matplotlib?

KhoaLearnToCode I'm having a problem here when trying to draw multiple lines on an image. So, here is my code: fig=plt.figure() final = cv2.imread('frame9.jpg') for p in polar: plt.plot([0,1],[p[0],p[0]],c='red') plt.imshow(final,cmap=plt.cm.gray) plt.show

How to draw lines on an image using matplotlib?

KhoaLearnToCode I'm having a problem here when trying to draw multiple lines on an image. So, here is my code: fig=plt.figure() final = cv2.imread('frame9.jpg') for p in polar: plt.plot([0,1],[p[0],p[0]],c='red') plt.imshow(final,cmap=plt.cm.gray) plt.show

How to draw curved and straight lines in one image?

stack I'm trying to draw a rectangle that is basically a circle, with a square on one end. Kind of like a battery. I have some limitations, basically this can only be done with a single paint object and should be able to support strokes. Here is my code so far

How to segment an image in OpenCV based on lines

ChiHong I am trying to do text segmentation. Attached below is its result. I managed to form lines to split the image. However, I'm stuck at splitting the image based on the lines I found. As marked in the attached image (red text), I want to split the image i

How to detect lines in an image using OpenCV in Java

Daniel Heberridge I have the code from the tutorial and I want to detect straight lines in an image. I have this code, but for 1 line HoughLinesP generates hundreds of points instead of 2 (start and end - [x1, y1] and [x2, y2]). Even if I use a blank image I g

opencv - draw contours in an image

learner I am trying to draw contours around an image. I can see that contours are found, but cannot draw contours. The color of the outline appears to be one of two (black and white). import cv2 import numpy as np import matplotlib.pyplot as plt from skimage i