Shift image content with OpenCV

后端 未结 9 1148
-上瘾入骨i
-上瘾入骨i 2020-12-08 04:36

Starting from an image, I would like to shift its content upward of 10 pixels, without changing size and filling in black the sub image (width x 10px) on the bo

9条回答
  •  -上瘾入骨i
    2020-12-08 05:08

    this link maybe help this question, thanks

    import cv2
    import numpy as np
    img = cv2.imread('images/input.jpg')
    num_rows, num_cols = img.shape[:2]   
    
    translation_matrix = np.float32([ [1,0,70], [0,1,110] ])   
    img_translation = cv2.warpAffine(img, translation_matrix, (num_cols, num_rows))   
    cv2.imshow('Translation', img_translation)    
    cv2.waitKey()
    

    and tx and ty could control the shift pixels on x and y direction respectively.

提交回复
热议问题