본문 바로가기

Python

example. numpy & cv2

import numpy
import cv2

arr = numpy.array([1,2,3,4,5,6,7,8,9]).reshape(3, 3)
print(arr)

# 행, 열
arr[0:2, 0] = 88
print(arr)

arr = numpy.arange(0, 100).reshape(10, 10)

print(arr)
print(arr.ndim)
print(arr[0].ndim)
print(len(arr))
print(len(arr[0]))

for i in range(len(arr)):
    arr[0:10-i, i] = -1
print(arr)


myimg = cv2.imread("test.jpg")
print(type(myimg))

row = len(myimg)
col = len(myimg[0])

print(type(myimg), row, col)

print(row)
for i in range(col):
    myimg[0:row-i, i] = [255, 255, 255]

cv2.imshow('test', myimg)
cv2.waitKey(0)


dd = numpy.full((row, col, 3), [255,255,255], dtype=numpy.uint8)
print(len(dd), len(dd[0]), type(dd), dd.dtype, myimg.dtype)
myimg2 = cv2.imread("test.jpg")
newimg = cv2.bitwise_xor(myimg2, dd)

cv2.imshow("test2", newimg)
cv2.waitKey(0)

'Python' 카테고리의 다른 글

기타 입력 처리 (map)  (0) 2024.08.20
[python] bearing  (0) 2024.03.27
[python] haversine distance  (0) 2024.03.27
python. io 성능  (0) 2023.10.04
python. shallow/deep copy  (0) 2023.10.04