Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何创建一个以一定角度显示图像堆栈的图形?_Python_Opencv_Matplotlib - Fatal编程技术网

Python 如何创建一个以一定角度显示图像堆栈的图形?

Python 如何创建一个以一定角度显示图像堆栈的图形?,python,opencv,matplotlib,Python,Opencv,Matplotlib,我正试图创造一个与之类似的人物 我曾尝试在OpenCV中使用透视变换,或在skimage中使用图像变换 import matplotlib.pyplot from skimage import transform # Load the image as a matrix image = io.imread("/path/to/your/image.jpg") # Create affine transform afine_tf = skimage.transform.AffineTrans

我正试图创造一个与之类似的人物

我曾尝试在OpenCV中使用透视变换,或在skimage中使用图像变换

import matplotlib.pyplot
from skimage import transform

# Load the image as a matrix
image = io.imread("/path/to/your/image.jpg")

# Create affine transform
afine_tf = skimage.transform.AffineTransform(shear=0.2)

# Apply transform to image data
modified = skimage.transform.warp(image, inverse_map=afine_tf)

不幸的是,我无法使用透视图达到预期效果。

您可以使用透视变换:

您必须更改此脚本,以便它使用您的图像,而不是生成纯色图像:

import cv2
import numpy as np

# Generate some images
images = []
w, h = 600,700
# Corners of images to be pasted onto background
pts2 = np.float32([[0,0],[w,0],[0,w],[w,w]])
for i in range(5):
    img = np.zeros((w,w,3), np.uint8)
    img[:,:,:] = i*42, 255, 255
    img = cv2.cvtColor(img, cv2.COLOR_HSV2BGR)
    images.append(img)

# Create a background
bg = np.zeros((w,h,3), np.uint8)

# Define where to paste the images
top, bottom, dx, width, middle, left_buffer = 100, 500, 100, 200, 300, 50
# Create a mask
mask = np.zeros((w,w), np.uint8)
mask[:] = 255
bg_zeros = np.zeros_like(bg)

# Paste the images onto the background
for i in range(5):
    # Get the image
    img = images[i]
    # Compute where to paste the image
    left = left_buffer+dx*i
    right = left_buffer+dx*i + width
    mid = int((left + right)/2)
    pts1 = np.float32([[mid, top], [right, middle],
                       [left, middle], [mid, bottom]])
    # Warp the image
    M = cv2.getPerspectiveTransform(pts2,pts1)
    dst = cv2.warpPerspective(img,M,(h,w))
    # Warp the mask and mask out the background
    cmask = cv2.warpPerspective(mask, M, (h,w))
    bg = cv2.bitwise_and(bg,bg,mask = 255-cmask)
    # Add the image to the background
    bg += dst
cv2.imshow('bg', bg)
cv2.waitKey()
cv2.destroyAllWindows()

好主意。很好的解决方案。