vision_camera · Camera and images¶
Takes pictures with the camera and edits images.
Class:
Camera
- class openpibo.vision_camera.Camera(cam=0, width=None, height=None)[source]¶
Bases:
objectFunctions:
imread()read()create_matte()imshow_to_ide()resize()rotate()imwrite()draw_bitmap()rectangle()circle()line()putTextPIL()putText()stylization()detailEnhance()pencilSketch()edgePreservingFilter()flip()Controls piBo’s camera.
Provides basic camera functions such as taking, reading and writing pictures.
Adds shapes/text to images.
Transforms images.
example:
from openpibo.vision_camera import Camera camera = Camera() # 아래의 모든 예제 이전에 위 코드를 먼저 사용합니다.
- imread(filename)[source]¶
Reads an image file.
- Parameters:
filename (str) – Image file to use
- Returns:
Image object of type
numpy.ndarray
- read()[source]¶
Captures an image with the camera. Changing the resolution may corrupt the image, so the default resolution is recommended.
- Returns:
Image object of type
numpy.ndarray
- imshow(img, ratio=1.0)[source]¶
Shows an image file in the Web IDE.
- Parameters:
img (numpy.ndarray) – Image object
ratio (float) – Image resize ratio (network load when many are used at once)
- imshow_to_ide(img, ratio=0.25)[source]¶
Shows an image file in the Web IDE.
- Parameters:
img (numpy.ndarray) – Image object
ratio (float) – Image resize ratio (network load when many are used at once)
- resize(img, w, h)[source]¶
Resizes an OpenCV image.
- Parameters:
img (numpy.ndarray) – Image object
w (int) – Width of the resized image (in pixels).
h (int) – Height of the resized image (in pixels).
- Returns:
Resized
numpy.ndarrayimage object
- rotate(img, degree=10, ratio=0.9)[source]¶
Rotates an image.
- Parameters:
img (numpy.ndarray) – Image object
degree (int) – Rotation angle
ratio (float) – Scale factor for shrinking or enlarging
- Returns:
Rotated
numpy.ndarrayimage object
- imwrite(filename, img)[source]¶
Saves an image to a file.
- Parameters:
filename (str) – Path of the file to save (jpg, png)
img (numpy.ndarray) – Image object to save
- draw_bitmap(w, h, val, background=(255, 255, 255), pixel=(0, 0, 0))[source]¶
Creates an image from bitmap (dot picture) data, enlarged to the camera image size.
- Parameters:
w (int) – Bitmap width
h (int) – Bitmap height
background (tuple) – Background color
pixel (tuple) – Bit color
- Returns:
numpy.ndarrayimage object
- rectangle(img, p1, p2, colors=(255, 255, 255), tickness=1)[source]¶
Draws a rectangle on an image.
- Parameters:
img (numpy.ndarray) – Image object
p1 (tuple(int, int)) – Top-left coordinates (x, y)
p2 (tuple(int, int)) – Bottom-right coordinates (x, y)
colors (tuple(int, int, int)) – BGR value (b, g, r) or hex value ‘#rrggbb’
tickness (int) – Thickness of the rectangle border (in pixels); -1 fills it
- circle(img, p, r, colors=(255, 255, 255), tickness=1)[source]¶
Draws a circle on an image.
- Parameters:
img (numpy.ndarray) – Image object
p (tuple(int, int)) – Top-left coordinates (x, y)
r (int) – Radius
colors (tuple(int, int, int)) – BGR value (b, g, r) or hex value ‘#rrggbb’
tickness (int) – Thickness of the circle outline (in pixels); -1 fills it
- line(img, p1, p2, colors=(255, 255, 255), tickness=1)[source]¶
Draws a straight line on an image.
- Parameters:
img (numpy.ndarray) – Image object
p1 (tuple(int, int)) – Start coordinates (x, y)
p2 (tuple(int, int)) – End coordinates (x, y)
colors (tuple(int, int, int)) – BGR value (b, g, r) or hex value ‘#rrggbb’
tickness (int) – Line thickness (in pixels)
- putTextPIL(img, text, points, size=30, colors=(255, 255, 255))[source]¶
Writes text on an image. (Korean/English supported - uses pillow)
- Parameters:
img (numpy.ndarray) – Image object
text (str) – Text to display
points (tuple(int, int)) – Top-left coordinates of the text block (x, y)
size (int) – Font size of the text
colors (tuple(int, int, int)) – Text color BGR value (b, g, r) or hex value ‘#rrggbb’
- putText(img, text, points, size=1, colors=(255, 255, 255), tickness=1)[source]¶
Writes text on an image. (English only)
- Parameters:
img (numpy.ndarray) – Image object
text (str) – Text to display
points (tuple(int, int)) – Bottom-left coordinates of the text block (x, y)
size (int) – Font size of the text
colors (tuple(int, int, int)) – Text color BGR value (b, g, r) or hex value ‘#rrggbb’
tickness (int) – Text thickness
- stylization(img, sigma_s=100, sigma_r=0.5)[source]¶
Converts to a cartoon image. (opencv api) low speed
- Parameters:
img (numpy.ndarray) – Image object
sigma_s (float) – Degree of blur preservation of the image (1-200)
sigma_r (float) – Degree of edge application of the image (0-1)
- Returns:
numpy.ndarrayimage object
- detailEnhance(img, sigma_s=100, sigma_r=0.05)[source]¶
Converts to a cartoon image. (opencv api)
- Parameters:
img (numpy.ndarray) – Image object
sigma_s (float) – Degree of blur preservation of the image (1-200)
sigma_r (float) – Degree of edge application of the image (0-1)
- Returns:
numpy.ndarrayimage object
- pencilSketch(img, sigma_s=100, sigma_r=0.2, shade_factor=0.018)[source]¶
Converts to a sketch image.
example:
img = camera.read() camera.sketchize(img)
- Parameters:
img (numpy.ndarray) – Image object
sigma_s (float) – Degree of blur preservation of the image (1-200)
sigma_r (float) – Degree of edge application of the image (0-1)
shade_factor (float) – Brightness level of the image (0-0.1)
- Returns:
numpy.ndarrayimage object / grayscale, bgr
- edgePreservingFilter(img, flags=1, sigma_s=60, sigma_r=0.4)[source]¶
Converts to a blurred image.
- Parameters:
img (numpy.ndarray) – Image object
flags (int) – Filter type 1 (RECURS_FILTER) or 2 (NORMCONV_FILTER)
sigma_s (float) – Degree of blur preservation of the image (1-200)
sigma_r (float) – Degree of edge application of the image (0-1)
- Returns:
numpy.ndarrayimage object