为什么图像结果翻转了90度?

问题描述 投票:0回答:1

我试图将此图像中的所有白色像素变成红色,但是当我运行程序时,形状很好,但红色像素旋转了 90 度(附上图像,因为我找不到更好的方法来解释这一点)。 代码的结果

这是我当前用来执行此操作的代码:

import cv2 as cv
import numpy as np
import os
from matplotlib import pyplot as plt
import cv2 as cv

def get_white_pixels(image_as_array):
    threshold = 40
    indices = np.where(image_as_array >= threshold)
    width=image.shape[1]
    height=image.shape[0]
    cartesian_y=height-indices[0]-1
    np_data_points=np.column_stack((indices[1],cartesian_y)) 
    return cartesian_y, np_data_points, width,height

image = cv.imread("framenumber0.jpg")
ind, pixels, width, height = get_white_pixels(image)

#Goes through every pixel and changes its values
for i in range(0, len(pixels)):
    loc_x = int(pixels[i][0])
    loc_y = int(pixels[i][1])
    image[loc_x,loc_y] = (0,0,255)

cv.imshow('Modified Image', image)
cv.waitKey(0)
cv.destroyAllWindows()

我确实需要白点的位置,因为稍后我将在项目的第二部分中使用它们。我怀疑这个问题与 np.column_stack() 有关。我一直在阅读该函数的信息页面,但我仍然不明白为什么会发生这种情况。

如果您想复制这里也是我正在使用的图像: 原图

python computer-vision pixel
1个回答
0
投票

更改线路:

    image[loc_y,loc_x] = (0,0,255)
© www.soinside.com 2019 - 2024. All rights reserved.