opencv / opencv-python

Automated CI toolchain to produce precompiled opencv-python, opencv-python-headless, opencv-contrib-python and opencv-contrib-python-headless packages.
https://pypi.org/project/opencv-python/
MIT License
4.43k stars 834 forks source link

Insufficient memory #957

Open Dhruv00710 opened 6 months ago

Dhruv00710 commented 6 months ago

sir I made OMR program in python version 3.11.4 32 bit version and its get problem about memory. and i am not use python 64 bit version because i also use twain library for scan OMR sheet and twain library is work on 32 bit and in 64 bit python its not show the scanner. so i use 32 bit library. Error like : res = cv2.matchTemplate( ^^^^^^^^^^^^^^^^^^ cv2.error: OpenCV(4.8.0) D:\a\opencv-python\opencv-python\opencv\modules\core\src\alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 4380856 bytes in function 'cv::OutOfMemoryError' and sir please replay me.

Sadegh-Kalami commented 6 months ago

did u find the solution?

Dhruv00710 commented 6 months ago

did u find the solution?

no i don't find solution. if you have any solution please give me.

Sadegh-Kalami commented 6 months ago

Well Iam trying to test opencv 4.5.4 or 4.2.0 they should work. I'll keep u in touch, but it may take a day to reach u. I suggest u to test 4.5.4.

Dhruv00710 commented 6 months ago

Well Iam trying to test opencv 4.5.4 or 4.2.0 they should work. I'll keep u in touch, but it may take a day to reach u. I suggest u to test 4.5.4.

ok. i try 4.5.4 version and after i tell you.

Dhruv00710 commented 6 months ago

4.5.4

i try version 4.5.4 and its get error like

Collecting opencv-python==4.5.4.60 Downloading opencv-python-4.5.4.60.tar.gz (89.8 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 89.8/89.8 MB 861.2 kB/s eta 0:00:00 Installing build dependencies ... error error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> [19 lines of output] Ignoring numpy: markers 'python_version == "3.6" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment Ignoring numpy: markers 'python_version == "3.7" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment Ignoring numpy: markers 'python_version == "3.8" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment Ignoring numpy: markers 'python_version <= "3.9" and sys_platform == "linux" and platform_machine == "aarch64"' don't match your environment
Ignoring numpy: markers 'python_version <= "3.9" and sys_platform == "darwin" and platform_machine == "arm64"' don't match your environment
Ignoring numpy: markers 'python_version == "3.9" and platform_machine != "aarch64" and platform_machine != "arm64"' don't match your environment Collecting setuptools Downloading setuptools-69.2.0-py3-none-any.whl.metadata (6.3 kB) Collecting wheel Downloading wheel-0.43.0-py3-none-any.whl.metadata (2.2 kB) Collecting scikit-build Downloading scikit_build-0.17.6-py3-none-any.whl.metadata (14 kB) Collecting cmake Downloading cmake-3.28.3-py2.py3-none-win32.whl.metadata (6.5 kB) Collecting pip Using cached pip-24.0-py3-none-any.whl.metadata (3.6 kB) ERROR: Ignored the following versions that require a different python version: 1.21.2 Requires-Python >=3.7,<3.11; 1.21.3 Requires-Python >=3.7,<3.11; 1.21.4 Requires-Python >=3.7,<3.11; 1.21.5 Requires-Python >=3.7,<3.11; 1.21.6 Requires-Python >=3.7,<3.11 ERROR: Could not find a version that satisfies the requirement numpy==1.21.2 (from versions: 1.3.0, 1.4.1, 1.5.0, 1.5.1, 1.6.0, 1.6.1, 1.6.2, 1.7.0, 1.7.1, 1.7.2, 1.8.0, 1.8.1, 1.8.2, 1.9.0, 1.9.1, 1.9.2, 1.9.3, 1.10.0.post2, 1.10.1, 1.10.2, 1.10.4, 1.11.0, 1.11.1, 1.11.2, 1.11.3, 1.12.0, 1.12.1, 1.13.0, 1.13.1, 1.13.3, 1.14.0, 1.14.1, 1.14.2, 1.14.3, 1.14.4, 1.14.5, 1.14.6, 1.15.0, 1.15.1, 1.15.2, 1.15.3, 1.15.4, 1.16.0, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5, 1.16.6, 1.17.0, 1.17.1, 1.17.2, 1.17.3, 1.17.4, 1.17.5, 1.18.0, 1.18.1, 1.18.2, 1.18.3, 1.18.4, 1.18.5, 1.19.0, 1.19.1, 1.19.2, 1.19.3, 1.19.4, 1.19.5, 1.20.0, 1.20.1, 1.20.2, 1.20.3, 1.21.0, 1.21.1, 1.22.0, 1.22.1, 1.22.2, 1.22.3, 1.22.4, 1.23.0rc1, 1.23.0rc2, 1.23.0rc3, 1.23.0, 1.23.1, 1.23.2, 1.23.3, 1.23.4, 1.23.5, 1.24.0rc1, 1.24.0rc2, 1.24.0, 1.24.1, 1.24.2, 1.24.3, 1.24.4, 1.25.0rc1, 1.25.0, 1.25.1, 1.25.2, 1.26.0b1, 1.26.0rc1, 1.26.0, 1.26.1, 1.26.2, 1.26.3, 1.26.4, 2.0.0b1) ERROR: No matching distribution found for numpy==1.21.2 [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Sadegh-Kalami commented 6 months ago

Iam already on half of the way of 4.5.4 :))

Sent from Outlook for Androidhttps://aka.ms/AAb9ysg


From: Dhruv00710 @.> Sent: Saturday, March 16, 2024 12:51:00 PM To: opencv/opencv-python @.> Cc: Sadegh Kalami @.>; Comment @.> Subject: Re: [opencv/opencv-python] Insufficient memory (Issue #957)

Well Iam trying to test opencv 4.5.4 or 4.2.0 they should work. I'll keep u in touch, but it may take a day to reach u. I suggest u to test 4.5.4.

ok. i try 4.5.4 version and after i tell you.

— Reply to this email directly, view it on GitHubhttps://github.com/opencv/opencv-python/issues/957#issuecomment-2001924301, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A7DNTQNMOBGHOD7QBNTFICLYYQFHZAVCNFSM6AAAAABDYSRR36VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBRHEZDIMZQGE. You are receiving this because you commented.Message ID: @.***>

Sadegh-Kalami commented 6 months ago

Oh darling I am sorry. I'm on linux platform. If u wanna try other opencv version u would better to build from source.

Dhruv00710 commented 6 months ago

Oh darling I am sorry. I'm on linux platform. If u wanna try other opencv version u would better to build from source.

which version i use.

Sadegh-Kalami commented 6 months ago

Tell me about your OS. to install opencv first:

sudo apt update
sudo apt install build-essential cmake git pkg-config libgtk-3-dev \
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \
gfortran openexr libatlas-base-dev python3-dev python3-numpy \
libtbb2 libtbb-dev libdc1394-22-dev
mkdir ~/opencv_build && cd ~/opencv_build
git clone https://github.com/opencv/opencv.git
cd opencv 
git checkout 4.2.0
cd ..
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout 4.2.0
cd ..
cd ~/opencv_build/opencv
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D INSTALL_C_EXAMPLES=ON \
      -D INSTALL_PYTHON_EXAMPLES=ON \
      -D OPENCV_GENERATE_PKGCONFIG=ON \
      -D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \
      -D BUILD_EXAMPLES=ON ..
make -j$(nproc)
sudo make install
sudo ldconfig
Dhruv00710 commented 6 months ago

Tell me about your OS. to install opencv first:

sudo apt update
sudo apt install build-essential cmake git pkg-config libgtk-3-dev \
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \
gfortran openexr libatlas-base-dev python3-dev python3-numpy \
libtbb2 libtbb-dev libdc1394-22-dev
mkdir ~/opencv_build && cd ~/opencv_build
git clone https://github.com/opencv/opencv.git
cd opencv 
git checkout 4.2.0
cd ..
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout 4.2.0
cd ..
cd ~/opencv_build/opencv
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D INSTALL_C_EXAMPLES=ON \
      -D INSTALL_PYTHON_EXAMPLES=ON \
      -D OPENCV_GENERATE_PKGCONFIG=ON \
      -D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \
      -D BUILD_EXAMPLES=ON ..
make -j$(nproc)
sudo make install
sudo ldconfig

i use windows 10 pro 64 bit operating system

Sadegh-Kalami commented 6 months ago

Finding out the bug took me 1 day and i didn't sleep 20hours. The problem for me was having 2 opencvs version. Libopencv-dev and custom installation of opencv 4.8.0. Choose 1 opencv and stick to it. GL

nanbwrn commented 3 weeks ago

hi, @Sadegh-Kalami If there are multiple versions of OpenCV installed on the system, how do you ensure that the version being used is the custom 4.8.0 version you installed? I would be extremely grateful, as I've tried many methods without success.

Sadegh-Kalami commented 3 weeks ago

hi, @nanbwrn You can use the command dpkg -l | grep libopencv to list all installed OpenCV packages and their versions. If your output looks like mine, where all packages are version 4.2, you're all set:

ii  libopencv-calib3d-dev:amd64                 4.2.0+dfsg-5                                amd64        development files for libopencv-calib3d4.2
ii  libopencv-calib3d4.2:amd64                  4.2.0+dfsg-5                                amd64        computer vision Camera Calibration library
ii  libopencv-contrib-dev:amd64                 4.2.0+dfsg-5                                amd64        development files for libopencv-contrib4.2
ii  libopencv-contrib4.2:amd64                  4.2.0+dfsg-5                                amd64        computer vision contrlib library
ii  libopencv-core-dev:amd64                    4.2.0+dfsg-5                                amd64        development files for libopencv-core4.2
ii  libopencv-core4.2:amd64                     4.2.0+dfsg-5                                amd64        computer vision core library
ii  libopencv-dev                               4.2.0+dfsg-5                                amd64        development files for opencv
ii  libopencv-dnn-dev:amd64                     4.2.0+dfsg-5                                amd64        development files for libopencv-dnn4.2
ii  libopencv-dnn4.2:amd64                      4.2.0+dfsg-5                                amd64        computer vision Deep neural network module
ii  libopencv-features2d-dev:amd64              4.2.0+dfsg-5                                amd64        development files for libopencv-features2d4.2
ii  libopencv-features2d4.2:amd64               4.2.0+dfsg-5                                amd64        computer vision Feature Detection and Descriptor Extraction library
ii  libopencv-flann-dev:amd64                   4.2.0+dfsg-5                                amd64        development files for libopencv-flann4.2
ii  libopencv-flann4.2:amd64                    4.2.0+dfsg-5                                amd64        computer vision Clustering and Search in Multi-Dimensional spaces library
ii  libopencv-highgui-dev:amd64                 4.2.0+dfsg-5                                amd64        development files for libopencv-highgui4.2
ii  libopencv-highgui4.2:amd64                  4.2.0+dfsg-5                                amd64        computer vision High-level GUI and Media I/O library
ii  libopencv-imgcodecs-dev:amd64               4.2.0+dfsg-5                                amd64        development files for libopencv-imgcodecs4.2
ii  libopencv-imgcodecs4.2:amd64                4.2.0+dfsg-5                                amd64        computer vision Image Codecs library
ii  libopencv-imgproc-dev:amd64                 4.2.0+dfsg-5                                amd64        development files for libopencv-imgproc4.2
ii  libopencv-imgproc4.2:amd64                  4.2.0+dfsg-5                                amd64        computer vision Image Processing library
ii  libopencv-ml-dev:amd64                      4.2.0+dfsg-5                                amd64        development files for libopencv-ml4.2
ii  libopencv-ml4.2:amd64                       4.2.0+dfsg-5                                amd64        computer vision Machine Learning library
ii  libopencv-objdetect-dev:amd64               4.2.0+dfsg-5                                amd64        development files for libopencv-objdetect4.2
ii  libopencv-objdetect4.2:amd64                4.2.0+dfsg-5                                amd64        computer vision Object Detection library
ii  libopencv-photo-dev:amd64                   4.2.0+dfsg-5                                amd64        development files for libopencv-photo4.2
ii  libopencv-photo4.2:amd64                    4.2.0+dfsg-5                                amd64        computer vision computational photography library
ii  libopencv-shape-dev:amd64                   4.2.0+dfsg-5                                amd64        development files for libopencv-shape4.2
ii  libopencv-shape4.2:amd64                    4.2.0+dfsg-5                                amd64        computer vision shape descriptors and matchers library
ii  libopencv-stitching-dev:amd64               4.2.0+dfsg-5                                amd64        development files for libopencv-stitching4.2
ii  libopencv-stitching4.2:amd64                4.2.0+dfsg-5                                amd64        computer vision image stitching library
ii  libopencv-superres-dev:amd64                4.2.0+dfsg-5                                amd64        development files for libopencv-superres4.2
ii  libopencv-superres4.2:amd64                 4.2.0+dfsg-5                                amd64        computer vision Super Resolution library
ii  libopencv-ts-dev:amd64                      4.2.0+dfsg-5                                amd64        development files for TS library of OpenCV (Open Computer Vision)
ii  libopencv-video-dev:amd64                   4.2.0+dfsg-5                                amd64        development files for libopencv-video4.2
ii  libopencv-video4.2:amd64                    4.2.0+dfsg-5                                amd64        computer vision Video analysis library
ii  libopencv-videoio-dev:amd64                 4.2.0+dfsg-5                                amd64        development files for libopencv-videoio4.2
ii  libopencv-videoio4.2:amd64                  4.2.0+dfsg-5                                amd64        computer vision Video I/O library
ii  libopencv-videostab-dev:amd64               4.2.0+dfsg-5                                amd64        development files for libopencv-videostab4.2
ii  libopencv-videostab4.2:amd64                4.2.0+dfsg-5                                amd64        computer vision video stabilization library
ii  libopencv-viz-dev:amd64                     4.2.0+dfsg-5                                amd64        development files for libopencv-viz4.2
ii  libopencv-viz4.2:amd64                      4.2.0+dfsg-5                                amd64        computer vision 3D data visualization library
ii  libopencv4.2-java                           4.2.0+dfsg-5                                all          Java bindings for the computer vision library
ii  libopencv4.2-jni                            4.2.0+dfsg-5                                amd64        Java jni library for the computer vision library

If you want to check the specific OpenCV version your project is using, you can add the following lines to your CMakeLists.txt:

find_package(OpenCV REQUIRED)

message(STATUS "Found OpenCV version: ${OpenCV_VERSION}")

When you run CMake, it will output the OpenCV version found, like this:

-- Found OpenCV version: 4.2.0