Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize picture zooming and mirroring by opencv

Shulou Source: shulou.com Published: 2022-06-01 14:08:03 09月26日 Update

This article mainly introduces how opencv realizes picture zooming and mirroring. The introduction in this article is very detailed and has certain reference value. Interested friends must read it!

An exercise code to zoom and then mirror an image:

import cv2

import numpy as np

#Open the original

img = cv2.imread("src.jpg", 1)

cv2.imshow("src",img)

#Get original information

imgInfo = img.shape

height = imgInfo[0]

width = imgInfo[1]

deep = imgInfo[2]

#The picture is too big, and the screen is not fully displayed after mirroring. Zoom here first.

matScale = np.float32([[0.8,0,0], [0,0.8,0]])

scale = cv2.warpAffine(img, matScale, (int(width*0.8), int(height*0.8)))

cv2.imshow("scale", scale)

#Re-capture the height and width of the zoomed image

imgInfo = scale.shape

height = imgInfo[0]

width = imgInfo[1]

#Image information mirrored

newImgInfo = (height * 2, width, deep)

dest = np.zeros(newImgInfo, np.uint8)

#Mirrors

for i in range(0, height):

for j in range(0, width):

dest[i,j] = scale[i,j]

dest[height*2 - i -1, j] = scale[i, j]

#Draw a mirror image of the original dividing line

for i in range(0, width):

dest[height, i] = (0,0,255)

cv2.imshow("dst", dest)

cv2.waitKey(0)

After the program runs, the effect is as follows:

The above is "opencv how to achieve image scaling and mirroring" all the content of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!

Tags: Mirrors pictures original images information content articles code values interests split lines guys partners effects more knowledge programs industry information information channels channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Linux Huawei Shulou Tech Info Microsoft