I don't see what's the purpose of your x variable. You don't need it.

Simply use:

img = cv2.imread('/path/to/Capture1.jpg',0)
rows,cols,_ = img.shape

for i in range(rows):
    for j in range(cols):
        k = img[i,j]
        print(k)

which will print indeed a vertical set of numbers. If you want to modify the values of the pixels use img.itemset(). http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_core/py_basic_ops/py_basic_ops.html

If you want to print the whole array then use print(img)

Answer from RMS on Stack Overflow
🌐
PyImageSearch
pyimagesearch.com › home › blog › opencv getting and setting pixels
OpenCV Getting and Setting Pixels - PyImageSearch
April 17, 2021 - Let’s now learn how to get and set individual pixel values using OpenCV! Be sure you have used the “Downloads” section of this tutorial to access the source code and example images. From there, you can execute the following command: $ python opencv_getting_setting.py --image adrian.png Pixel at (0, 0) - Red: 233, Green: 240, Blue: 246 Pixel at (50, 20) - Red: 229, Green: 238, Blue: 245 Pixel at (50, 20) - Red: 255, Green: 0, Blue: 0
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-opencv-getting-and-setting-pixels
Python OpenCV - Getting and Setting Pixels - GeeksforGeeks
July 23, 2025 - # import the cv2 package import cv2 # read the image img = cv2.imread('image.png') for i, row in enumerate(img): # get the pixel values by iterating for j, pixel in enumerate(img): if(i == j or i+j == img.shape[0]): # update the pixel value ...
🌐
Towards Data Science
towardsdatascience.com › home › latest › working with image pixels in opencv
Working with Image Pixels in OpenCV | Towards Data Science
March 5, 2025 - The total number of pixels in an image is obtained as the product of its height, width and channels. Since Images in OpenCV are read as Numpy arrays of pixel values, it is then possible to get and process regions of an image as represented by ...
🌐
TutorialsPoint
tutorialspoint.com › how-to-access-and-modify-pixel-value-in-an-image-using-opencv-python
How to access and modify pixel value in an image using OpenCV Python?
December 2, 2022 - To access a single pixel value in an image we can use indexing the same as we do to NumPy array indexing. We can use slicing to access a sequence of pixel values. To modify the pixel values we use the simple Python assignment operator ("="). Steps T
🌐
Master Data Science
datahacker.rs › how-to-access-and-edit-pixel-values-in-opencv-with-python
#000 How to access and edit pixel values in OpenCV with Python?
November 14, 2020 - Then, we will actually reverse the coordinates when we want to work with them as matrices both in OpenCV and NumPy. Pixels coordinates when we work with NumPy matrices/images · We can assess and manipulate each pixel in an image in a similar way: as an individual element of an array referenced in Python.
🌐
Quora
quora.com › How-can-I-extract-pixel-values-from-an-image-and-retrieve-the-same-image-again-in-OpenCV-Python
How to extract pixel values from an image and retrieve the same image again in OpenCV Python - Quora
Answer: import cv2 import csv import numpy as np def pic_data_strip_csv(): img = cv2.imread(r"image-path") img_height, img_width = img.shape[:2] for x in range (0, img_height,1): for y in range (0,img_width,1): pixel_value = img[x,y,:] with open(r"csv-file-path",mode="a") as pic_data: p...
🌐
Indian AI Production
indianaiproduction.com › home › blog › get image pixels using opencv python | opencv tutorial in hindi
Get Image Pixels Using OpenCV Python | OpenCV Tutorial in Hindi
August 8, 2021 - # Import Library import cv2 import numpy as np # Read & Show Image img_path = r"C:\Users\kashz\AI Life\AI Projects - IAIP, PTs (Web + Channel)\02 OpenCV\000 opencv tutorial\data\pexels-rafi-ahmed-haven-1253364.jpg" img = cv2.imread(img_path) img = cv2.resize(img,(int(img.shape[1]*0.5), int(img.shape[0]*0.5))) cv2.imshow("image", img) cv2.waitKey(0) cv2.destroyAllWindows() img img.shape 959*640 img.size · # # Access Single Pixel of Image img[0,0] img[0,0, 0] img[0,0, 1] img[0,0, 2] img[0][0] img[200,100] img[900, 150] img[180, 550] # # Show single pixel of Image as Image cv2.imshow("image", img[900, 150]) cv2.waitKey(0) cv2.destroyAllWindows()
🌐
OpenCV
docs.opencv.org › 4.13.0 › d3 › df2 › tutorial_py_basic_ops.html
OpenCV: Basic Operations on Images
( Examples will be shown in a Python terminal, since most of them are just single lines of code ) ... Loads an image from a file. You can access a pixel value by its row and column coordinates. For BGR image, it returns an array of Blue, Green, Red values.
Find elsewhere
🌐
ProjectPro
projectpro.io › recipes › read-image-opencv-and-read-pixel-it
How to read an image using OpenCV and read a pixel in it -
February 20, 2023 - These parameters can also be passed as integers such as 1, -1, and 0, respectively. The default flag value is 1. Let us try to read an image in colored format. ... If we print the image variable, we can see the pixel values of the image like this.
🌐
YouTube
youtube.com › watch
OpenCV Python Read And Write Pixels - YouTube
🎁 Get FREE Robotics & AI Resources (Guide, Textbooks, Courses, Resume Template, Code & Discounts) – Sign up via the pop-up at https://kevinwoodrobotics.com/...
Published: May 25, 2023
🌐
Computer Vision
cvexplained.wordpress.com › accessing-pixels
Accessing Pixels & ROI - Computer Vision - WordPress.com
August 6, 2020 - ... # Image Properties print('The shape of the Image is: {}'.format(img.shape)) print('The size of the Image is: {} You can get this value by doing cols * rows * channels'.format(img.size)) print('The data type of the Image is: {}'.format(i...
🌐
YouTube
youtube.com › notes2learn
Lecture 3 Accessing image pixels and planes OpenCV Python - YouTube
Accessing the pixels in an image, planes in an image and computing the size and shape of the image.https://github.com/manjaryp/DIP_OpenCV_Python/tree/master/...
Published: January 16, 2018
Views: 18K
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to access and modify pixel values in an image using opencv python
5 Best Ways to Access and Modify Pixel Values in an Image Using OpenCV Python - Be on the Right Side of Change
February 27, 2024 - The simplest way to access or modify the value of a single pixel in an image using OpenCV is by specifying its position with x and y coordinates. The cv2.imread() function is used to read in the image, after which a pixel’s value can be accessed ...
🌐
YouTube
youtube.com › er karan arora
How to Extract the RGB Values of a Pixel in OpenCV using Python - YouTube
In this video, I'll show you How to Extract the RGB Values of a Pixel in OpenCV using Python#OpenCV #OpenCVPython OpenCVTutorials #Python #ComputerVision►Itr...
Published: July 13, 2021
Views: 7K
🌐
YouTube
youtube.com › watch
OpenCV Tutorials # 4 : How to access and edit pixel values in open cv - YouTube
This video will show you how we can access and edit pixel values of image using Open CV library.Two functions are discussed item, itemset
Published: March 9, 2019
🌐
YouTube
youtube.com › watch
Accessing & Modifying Image Pixels --OpenCV(Python) - YouTube
Code to display Image using matplotlibimport matplotlib.pyplot as pltfix_image=cv2.cvtColor(img,cv2.COLOR_BGR2RGB);plt.imshow(fix_image)Learn Complete Image ...
Published: January 7, 2021
🌐
Bogotobogo
bogotobogo.com › python › OpenCV_Python › python_opencv3_basic_image_operations_pixel_access_image_load.php
Python Tutorial - Basic Image Operations pixel access - 2020
img.dtype (usually, dtype=np.uint8) ... does not contain any channels. The number of channels for ARGB = 4. ... We can access a pixel value by its row and column coordinates....
🌐
FutureLearn
futurelearn.com › home › blog
Practical: Getting and setting image pixel values using Python OpenCV
October 25, 2022 - It’s common to process and analyse images purely using Python, rather than through via Fiji. The OpenCV library is one way to do this. This practical shows you how to install OpenCV if you haven’t already, then how to open images and manipulate pixel values within them.
🌐
OpenCV-Python Tutorials
opencv24-python-tutorials.readthedocs.io › en › latest › py_tutorials › py_core › py_basic_ops › py_basic_ops.html
Basic Operations on Images — OpenCV-Python Tutorials beta documentation
Image properties include number of rows, columns and channels, type of image data, number of pixels etc. Shape of image is accessed by img.shape. It returns a tuple of number of rows, columns and channels (if image is color): ... If image is grayscale, tuple returned contains only number of rows and columns. So it is a good method to check if loaded image is grayscale or color image. ... img.dtype is very important while debugging because a large number of errors in OpenCV-Python code is caused by invalid datatype.