Your code can be fixed as follows:

import numpy as np, cv
vis = np.zeros((384, 836), np.float32)
h,w = vis.shape
vis2 = cv.CreateMat(h, w, cv.CV_32FC3)
vis0 = cv.fromarray(vis)
cv.CvtColor(vis0, vis2, cv.CV_GRAY2BGR)

Short explanation:

  1. np.uint32 data type is not supported by OpenCV (it supports uint8, int8, uint16, int16, int32, float32, float64)
  2. cv.CvtColor can't handle numpy arrays so both arguments has to be converted to OpenCV type. cv.fromarray do this conversion.
  3. Both arguments of cv.CvtColor must have the same depth. So I've changed source type to 32bit float to match the ddestination.

Also I recommend you use newer version of OpenCV python API because it uses numpy arrays as primary data type:

import numpy as np, cv2
vis = np.zeros((384, 836), np.float32)
vis2 = cv2.cvtColor(vis, cv2.COLOR_GRAY2BGR)
Answer from Andrey Kamaev on Stack Overflow
🌐
Medium
medium.com › @carlosdnotes › create-numpy-images-with-opencv-4b512d5993e4
Create NumPy Images with OpenCV. Create, display, and save images with… | by CarlosD | Medium
October 27, 2025 - Once you set up OpenCV as described in my previous post, go to your main.py file. Replace everything inside that file with the following code: #!/usr/bin/env python3 import cv2 as cv import numpy as np def main(): # Set image size, in pixels rows = 6 columns = 8 # Create images black_image = np.ones((rows, columns), dtype=np.uint8) gray_image = np.ones((rows, columns), dtype=np.uint8) * 128 white_image = np.ones((rows, columns), dtype=np.uint8) * 255 # Write images to a file cv.imwrite("./images/black_image.jpg", black_image) cv.imwrite("./images/gray_image.jpg", gray_image) cv.imwrite("./images/white_image.jpg", white_image) # Render…
🌐
GitHub
github.com › opencv › opencv-python › issues › 943
Numpy 2 compatible build · Issue #943 · opencv/opencv-python
January 3, 2024 - # create a virtualenv $ python -m venv testvenv # install numpy 2.x $ testvenv/bin/pip install --pre -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy # install opencv-python-rolling $ testvenv/bin/pip install opencv-python-rolling $ testvenv/bin/python >>> import cv2 RuntimeError: module compiled against ABI version 0x1000009 but this version of numpy is 0x2000000 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/share/dev/src/testvenv/lib/python3.10/site-packages/cv2/__init__.py", line 181, in <module> bootstrap() File "/share/dev/src/test
Author: opencv
Discussions

python - Converting Numpy Array to OpenCV Array - Stack Overflow
I'm trying to convert a 2D Numpy array, representing a black-and-white image, into a 3-channel OpenCV array (i.e. an RGB image). Based on code samples and the docs I'm attempting to do this via Py... More on stackoverflow.com
🌐 stackoverflow.com
When will opencv-python support numpy 2.0?
Our paddle requires support for numpy 2.0, but paddle uses opencv-python. If paddle is compiled with numpy 2.0, it will conflict with opencv-python compiled under numpy 1.0. More on github.com
🌐 github.com
June 11, 2024
python - Numpy and OpenCV - Stack Overflow
I'm tired to import cv and numpy and get errors. I started importing cv and I got this error: ImportError: numpy.core.multiarray failed to import Traceback (most recent call last): File "",... More on stackoverflow.com
🌐 stackoverflow.com
CUDA, CuPy & OpenCV from Source with Numpy 2.2.6 on JetPack 6.1
The trouble I encounter is that importing cv2 in Python3 fails because OpenCV is built against the Numpy 1.x.x ABI, but I need to have Numpy 2.x.x installed. Situation details: CuPy installed using python3 -m pip install cupy-cuda12x, which installs NumPy 2.2.6 as a dependency. More on forums.developer.nvidia.com
🌐 forums.developer.nvidia.com
1
0
February 23, 2026
🌐
DataSource.ai
datasource.ai › en › data-science-articles › numpy-opencv-in-action
Numpy & OpenCV In Action
May 4, 2020 - To get Numpy just use this command "pip install numpy" in the command line of your computer. In the link below, you can find a brief description. ... Similarly for OpenCV, we can use this command "pip install opencv-python".
🌐
Analytics Vidhya
analyticsvidhya.com › home › advanced opencv and numpy operations: cropping, copying, and pasting
Advanced OpenCV and NumPy Operations: Cropping, Copying, And Pasting
July 28, 2021 - As we already know, OpenCV represents an image as a NumPy array comprising integers that represent the pixels and intensity- hence, by indexing and slicing portions of the NumPy array, we are essentially isolating specific pixels thereby isolating ...
🌐
YouTube
youtube.com › watch
OpenCV Numpy Basics - Image Data Structure - Raspberry Pi - YouTube
Learn how images are structured for processing in OpenCV and learn the very basics of Numpy for use in Open CV. After this video, you will understand how Num...
Published: October 2, 2024
🌐
OpenCV
docs.opencv.org › 4.13.0 › d0 › de3 › tutorial_py_intro.html
OpenCV: Introduction to OpenCV-Python Tutorials
OpenCV-Python makes use of Numpy, which is a highly optimized library for numerical operations with a MATLAB-style syntax. All the OpenCV array structures are converted to and from Numpy arrays.
Find elsewhere
🌐
OpenCV
docs.opencv.org › 4.13.0 › d3 › df2 › tutorial_py_basic_ops.html
OpenCV: Basic Operations on Images
cv.split() is a costly operation (in terms of time). So use it only if necessary. Otherwise go for Numpy indexing.
🌐
GitHub
github.com › opencv › opencv-python › issues › 997
When will opencv-python support numpy 2.0? · Issue #997 · opencv/opencv-python
June 11, 2024 - OpenCV team works on new packages release. As short term solution you can re-build OpenCV-Python package with Numpy 2 from sources.
🌐
Medium
medium.com › analytics-vidhya › images-manipulations-using-opencv-numpy-and-python-2e5538d35614
Image Manipulations using OpenCV, Numpy and Python | by Venkatesh | Analytics Vidhya | Medium
June 28, 2020 - Image Manipulations using OpenCV, Numpy and Python OpenCV was started at Intel in 1999 by Gary Bradsky, and the first release came out in 2000. Vadim Pisarevsky joined Gary Bradsky to manage …
🌐
NVIDIA Developer Forums
forums.developer.nvidia.com › robotics & edge computing › jetson systems › jetson orin nano
CUDA, CuPy & OpenCV from Source with Numpy 2.2.6 on JetPack 6.1 - Jetson Orin Nano - NVIDIA Developer Forums
February 23, 2026 - The trouble I encounter is that importing cv2 in Python3 fails because OpenCV is built against the Numpy 1.x.x ABI, but I need to have Numpy 2.x.x installed. Situation details: CuPy installed using python3 -m pip install cupy-cuda12x, which installs NumPy 2.2.6 as a dependency.
🌐
Medium
sudhanshunamdev45.medium.com › creating-and-displaying-an-image-using-numpy-and-opencv-in-python-a37e0cb503c7
Creating and Displaying an Image using NumPy and OpenCV in Python | by Sudhanshu Namdev | Medium
August 2, 2023 - We’ll create a 3-dimensional NumPy array with all zeros, where the shape of the array is (height, width, 3). The “3” in the shape represents the three color channels: Red, Green, and Blue (RGB). ... Step 4: Displaying the Image To display the image, we will use the OpenCV library.
🌐
Stack Exchange
raspberrypi.stackexchange.com › questions › 145379 › opencv-pandas-and-numpy
OpenCV Pandas and Numpy - Raspberry Pi Stack Exchange
Defaulting to user installation because normal site-packages is not writeable Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting opencv-python Using cached opencv-python-4.8.1.78.tar.gz (92.1 MB) Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Requirement already satisfied: numpy>=1.19.3 in ./.local/lib/python3.9/site-packages (from opencv-python) (1.26.2) Building wheels for collected packages: opencv-python Building wheel for opencv-python (pyproject.toml) ...
🌐
KDnuggets
kdnuggets.com › 2018 › 07 › basic-image-data-analysis-numpy-opencv-p1.html
Basic Image Data Analysis Using Numpy and OpenCV – Part 1 - KDnuggets
imageio.imread loads image as RGB (or RGBA), but OpenCV assumes the image to be BGR or BGRA (BGR is the default OpenCV colour format).
🌐
The Neural Base
theneuralbase.com › home › opencv › advanced course › opencv to numpy
OpenCV to NumPy | Opencv Advanced Course | The Neural Base
OpenCV images are NumPy arrays under the hood. When you load an image with cv2.imread(), you get a NumPy ndarray with shape (height, width, channels) and dtype uint8 (for 8-bit images). The pixel data is stored in memory as a C-contiguous array in BGR order by default, not RGB: this is critical ...
🌐
GitHub
github.com › spillai › numpy-opencv-converter
GitHub - spillai/numpy-opencv-converter: OpenCV <=> NumPy Converter using Boost::Python
September 14, 2014 - A convenience library that registers a boost::python converter to implicitly convert between OpenCV's popular cv::Mat datatype and NumPy's popular np.array() datatype.
Starred by 132 users
Forked by 52 users
Languages: C++ 91.8% | CMake 8.2% | C++ 91.8% | CMake 8.2%
🌐
Medium
medium.com › data-science › getting-started-with-numpy-and-opencv-for-computer-vision-555f88536f68
Getting Started with NumPy and OpenCV for Computer Vision (CV-01)
May 9, 2023 - The OpenCV library makes image processing and computer vision easier. The NumPy library works in the root level of image formation as it works with arrays.
🌐
Medium
anjalisingh-ratan.medium.com › image-manipulation-and-processing-using-opencv-and-numpy-d4e5404f3ddd
Image Manipulation and processing using OpenCV and NumPy | by Anjali Singh | Medium
June 12, 2021 - There is a special open source ... and more. Written in C++, it also comes with Python wrapper and can work in tandem with NumPy, SciPy, and Matplotlib....
🌐
Quora
quora.com › What-is-the-difference-between-OpenCV-and-numpy-in-image-and-real-time-analysis
What is the difference between OpenCV and numpy in image and real time analysis? - Quora
Answer: OpenCV stands for Open source Computer Vision. NumPy stands for Numerical Python. As the names suggest, OpenCV is used to image processing and other computer vision tasks like contour detection, seam estimation, optical flow etc. NumPy on the other hand is used to numerical purposes li...