Cv2 draw point python

Cv2 draw point python

Drawing functions work with matrices/images of arbitrary depth. The boundaries of the shapes can be rendered with antialiasing (implemented only for 8-bit images for now). All the functions include the parameter color that uses an RGB value (that may be constructed with the Scalar constructor ) for color images and brightness for grayscale images. For color images, the channel ordering is normally Blue, Green, Red. This is what imshow, imread, and imwrite expect. So, if you form a color using the Scalar constructor, it should look like:

\[\texttt (blue \_ component, green \_ component, red \_ component[, alpha \_ component])\]

If you are using your own image rendering and I/O functions, you can use any channel ordering. The drawing functions process each channel independently and do not depend on the channel order or even on the used color space. The whole image can be converted from BGR to RGB or to a different color space using cvtColor .

If a drawn figure is partially or completely outside the image, the drawing functions clip it. Also, many drawing functions can handle pixel coordinates specified with sub-pixel accuracy. This means that the coordinates can be passed as fixed-point numbers encoded as integers. The number of fractional bits is specified by the shift parameter and the real point coordinates are calculated as \(\texttt(x,y)\rightarrow\texttt(x*2^,y*2^)\) . This feature is especially effective when rendering antialiased shapes.

Note The functions do not support alpha-transparency when the target image is 4-channel. In this case, the color[3] is simply copied to the repainted pixels. Thus, if you want to paint semi-transparent shapes, you can paint them in a separate buffer and then blend it with the main image.

Читайте также:  Java как собрать exe

Macro Definition Documentation

◆ CV_RGB

OpenCV color channel order is BGR[A]

Источник

Русские Блоги

Используйте встроенный opencvФункция circle () может рисовать круг с определенным радиусом с точкой в ​​центре., Объявление функции выглядит следующим образом:

cv2.circle(img, center, radius, color[, thickness[, lineType[, shift]]])

Смысл параметров функции следующий:

  • img: прямоугольник или изображение, на котором расположен круг, который нужно нарисовать
  • center: координаты центра круга, например (100, 100)
  • радиус: радиус, например 10
  • color: цвет границы круга, например (0, 0, 255) красный, BGR
  • Толщина: положительное значение означает ширину границы круга. Отрицательное значение означает рисование закрашенного круга.
  • lineType: тип круглой границы, может быть 0, 4, 8
  • shift: количество десятичных знаков для координаты центра и радиуса

Чтобы нарисовать точку, на самом деле нужно нарисовать сплошной круг с небольшим радиусом. Полный код для рисования точки и круга выглядит следующим образом:

#!/usr/bin/python # -*- coding: UTF-8 -*- import numpy as np import cv2 as cv img = np.zeros ((320, 320, 3), np.uint8) # Создать пустое изображение в оттенках серого print img.shape # Вывод: (480, 480, 3) point_size = 1 point_color = (0, 0, 255) # BGR толщина = 4 # может быть 0, 4, 8 # Координаты точки, которую нужно нарисовать points_list = [(160, 160), (136, 160), (150, 200), (200, 180), (120, 150), (145, 180)] for point in points_list: cv.circle(img, point, point_size, point_color, thickness) # Нарисуйте круг, центр: (160, 160), радиус: 60, цвет: point_color, сплошная линия cv.circle(img, (160, 160), 60, point_color, 0) cv.namedWindow("image") cv.imshow('image', img) cv.waitKey (10000) # Отображение 10000 мс, то есть исчезает через 10 с cv.destroyAllWindows()

Источник

Оцените статью