opencv

Published by onesixx on

image를 jupyter에 표기

import cv2
import numpy as np

# Create a black canvas (image) to draw on
height, width = 500, 500
canvas = np.zeros((height, width, 3), dtype='uint8')

# Define the rectangle's top-left and bottom-right coordinates
rect_top_left = (100, 100)
rect_bottom_right = (400, 300)

# Define the rectangle's color (BGR format)
rect_color = (0, 255, 0)  # Green color

# Draw the rectangle on the canvas
cv2.rectangle(canvas, rect_top_left, rect_bottom_right, rect_color, thickness=2)


# Display the canvas with the rectangle
# cv2.imshow('Rectangle', canvas)
# cv2.waitKey(0)
# cv2.destroyAllWindows()


from IPython.display import display, Image

# Convert the BGR image to RGB format
canvas_rgb = cv2.cvtColor(canvas, cv2.COLOR_BGR2RGB)


# Save the image to a file
# display(Image(data=canvas_rgb))

cv2.imwrite('rectangle_image.jpg', canvas_rgb)
display(Image(filename='rectangle_image.jpg'))

imshow

NumPy 배열을 Python의 이미지로 저장

이미지 보기 : opencv

import cv2

imgPath = osp.join(DATA_DIR, IMG_PREFIX,'000068.jpeg')
img_array = cv2.imread(imgPath)

이미지 보기 : Matplotlib

https://kimtaeuk0103.tistory.com/28

import matplotlib.pyplot as plt

fileNm = '/home/sixx/my/git/mmdetection/data/cowboy/iomages/a0b1a049a1a27fff.jpg'

img_color = plt.imread(fileNm)
plt.imshow(img_color)
plt.show()

Categories: vision

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x