글

Animation #1 - Simple animation using numpy

이미지
Yesterday, I wrote a blog post on rotating an image with OpenCV . I will explain how to create a simple animation using the rotate and pan functions of an image. I hope this learning will give you a deeper opportunity to learn more about OpenCV and numpy. Basic concept Add an overlay image to the right of the canvas image. As time goes, rotate the overlay image and move it to the left. You need a bit of math knowledge to create natural animations. Angular Velocity Angular velocity refers to how fast an object rotates or revolves relative to another point, i.e. how fast the angular position or orientation of an object changes with time. I'm going to make an 30 FPS(frame per second)  animation. Thus, the time per frame is 1/30 seconds (0.0333). If it takes 2 seconds to rotate the image 360 ​​degrees, the angular velocity is π (radian)/sec. Thus, the angle traveled for 1/30 second is π (radian) / 30, and the distance that the circle rolled is R x  π (radian) / 30....

Image Processing #4 - WaterMark without alpha channel

이미지
A few days ago, I wrote a blog post on pasting overlays with OpenCV . A little tweaking the code in that article can create a watermark feature. Many Python samples that implement watermarks use the alpha channel of png files. However, I would like to implement the function of generating a watermark using an image of an RGB channel without an alpha channel. Masking code in my previous blog def process_masking (base, mask, pos): h, w, c = mask . shape hb, wb, _ = base . shape x = pos[ 0 ] y = pos[ 1 ] #check mask position if (x > wb or y > hb): print( ' invalid overlay position(%d,%d)' % (x, y)) return None #remove alpha channel if c == 4 : mask = cv2 . cvtColor(mask, cv2 . COLOR_BGRA2BGR) #adjust mask if (x + w > wb): mask = mask[:, 0 :wb - x] print( ' mask X size adjust[W:%d] -> [W:%d]' % (w, wb - x...

Image Processing #3 - Rotate

이미지
Sample codes are in my Repo . Rotate image Rotation using cv2.warpAffine import argparse import cv2 import numpy as np parser = argparse . ArgumentParser(description = "OpenCV Example" ) parser . add_argument( "--file" , type = str, required = True , help = "filename of the input image to process" ) parser . add_argument( "--angle" , type = int, required = True , help = "rotate angle(degree)" ) args = parser . parse_args() img = cv2 . imread(args . file, cv2 . IMREAD_COLOR) height, width, channels = img . shape print( "image H:%d W:%d, Channel:%d" % (height, width, channels)) cv2 . imshow( 'original' , img) matrix = cv2 . getRotationMatrix2D((width / 2 , height / 2 ), args . angle, 1 ) img = cv2 . warpAffine(img, matrix, (width, height)) height, width, channels = img . shape print( "rotate image H:%d W:%d, Channel:%d" % (height, width, c...

Image Processing #2 - Shift

이미지
Sample codes are in my Repo . Move image to left, right, top, bottom. Translation using cv2.warpAffine import argparse import cv2 import numpy as np parser = argparse . ArgumentParser(description = "OpenCV Example" ) parser . add_argument( "--file" , type = str, required = True , help = "filename of the input image to process" ) parser . add_argument( "--x" , type = int, required = True , help = "shift value of X direction" ) parser . add_argument( "--y" , type = int, required = True , help = "shift value of Y direction" ) args = parser . parse_args() img = cv2 . imread(args . file, cv2 . IMREAD_COLOR) height, width, channels = img . shape print( "image H:%d W:%d, Channel:%d" % (height, width, channels)) cv2 . imshow( 'original' , img) translation_matrix = np . float32([ [ 1 , 0 ,args . x], [ 0 , 1 ,args . y] ]) img_translation = cv2 ...