본문 바로가기

전체 글

ch04 trackbar #python codeimport cv2import numpy as npdef on_level_change(pos, img): img[:] = pos * 16 cv2.imshow("image", img)def main(): img = np.zeros((400, 400), dtype=np.uint8) cv2.namedWindow("image") cv2.createTrackbar("level", "image", 0, 16, lambda pos: on_level_change(pos, img)) cv2.imshow("image", img) cv2.waitKey()if __name__ == "__main__": main()// C++ code#include "opencv.. 더보기
ch04 trackbar #python codeimport cv2import numpy as npdef on_level_change(pos, img): img[:] = pos * 16 cv2.imshow("image", img)def main(): img = np.zeros((400, 400), dtype=np.uint8) cv2.namedWindow("image") cv2.createTrackbar("level", "image", 0, 16, lambda pos: on_level_change(pos, img)) cv2.imshow("image", img) cv2.waitKey()if __name__ == "__main__": main()// C++ code#include "opencv.. 더보기
ch04 storage #python codeimport cv2import numpy as np# 파일 이름 설정filename = "mydata.json"def writeData(): name = "Jane" age = 10 pt1 = (100, 200) scores =np.array([80, 90, 50], dtype=np.int32) mat1 = np.array([[1.0, 1.5], [2.0, 3.2]], dtype=np.float32) fs = cv2.FileStorage(filename, cv2.FileStorage_WRITE) if not fs.isOpened(): print("File open failed!") return fs.write("na.. 더보기
ch04 mouse #python codeimport cv2# 전역 변수 선언img = NoneptOld = Nonedef on_mouse(event, x, y, flags, param): global ptOld, img if event == cv2.EVENT_LBUTTONDOWN: ptOld = (x, y) print(f"EVENT_LBUTTONDOWN: {x}, {y}") elif event == cv2.EVENT_LBUTTONUP: print(f"EVENT_LBUTTONUP: {x}, {y}") elif event == cv2.EVENT_MOUSEMOVE: if flags & cv2.EVENT_FLAG_LBUTTON: cv2.l.. 더보기
ch04 keyboard #python code import cv2def main(): img = cv2.imread("D:\\projects\\SampleCode\\006939-master\\ch04\\keyboard\\lenna.bmp") if img is None: print("Image load failed!") return -1 cv2.namedWindow("img") cv2.imshow("img", img) while True: keycode = cv2.waitKey() if keycode == ord('i') or keycode == ord('I'): img = ~img cv2.imshow("img",.. 더보기
ch04 drawing #python codeimport cv2import numpy as npdef drawLines(): img = np.full((400, 400, 3), (255, 255, 255), dtype=np.uint8) cv2.line(img, (50, 50), (200, 50), (0, 0, 255)) cv2.line(img, (50, 100), (200, 100), (255, 0, 255), 3) cv2.line(img, (50, 150), (200, 150), (255, 0, 0), 10) cv2.line(img, (250, 50), (350, 100), (0, 0, 255), 1, cv2.LINE_4) cv2.line(img, (250, 70), (350, 120), (2.. 더보기
ch03 ScalarOp #python codeimport cv2import numpy as npdef VecOp(): p1 = np.zeros(3, dtype=np.uint8) # Vec3b equivalent p2 = np.array([0, 0, 255], dtype=np.uint8) # Vec3b equivalent p1[0] = 100 print("p1:", p1) print("p2:", p2)def ScalarOp(): gray = np.array([128, 128, 128], dtype=np.uint8) # Scalar equivalent print("gray:", gray) yellow = np.array([0, 255, 255], dtype=np.uint8) # S.. 더보기
ch03 MatOp import cv2import numpy as npdef MatOp1(): img1 = np.empty((0, 0), dtype=np.uint8) # empty matrix img2 = np.zeros((480, 640), dtype=np.uint8) # unsigned char, 1-channel img3 = np.zeros((480, 640, 3), dtype=np.uint8) # unsigned char, 3-channels img4 = np.zeros((480, 640, 3), dtype=np.uint8) # Size(width, height) img5 = np.full((480, 640), 128, dtype=np.uint8) # initial values, .. 더보기