Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23276

Why is the image result flipped by 90 degrees?

$
0
0

I am trying to turn all of the white pixels in this image red, but when I run the program the shape is fine but the red pixels are rotated 90 degrees:

result

This is the current code that I am using to do this:

import cv2 as cvimport numpy as npimport osfrom matplotlib import pyplot as pltimport cv2 as cvdef 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,heightimage = cv.imread("framenumber0.jpg")ind, pixels, width, height = get_white_pixels(image)#Goes through every pixel and changes its valuesfor 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()

I do need the location of the white points as I will use them later for the second part of the project. I suspect the problem has something to do with the np.column_stack(). I have been reading the info page of the function but I still do not understand why this happens.

If you want to replicate here is also the image that I am using:

source


Viewing all articles
Browse latest Browse all 23276

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>