After importing opencv-python , the corresponding functions don't work - opencv

I'm new to learning on opencv-python.
So I started by creating a new python project named OpenCV and then imported opencv-python package and then started typing in my code in a new Python file. But once I try running the file I keep getting error.
Code And Error img
It seems as if imread() and imshow() - none are accepted.
I tried importing imread() separately by using cmd and my terminal but nothing seems to works.
It further shows legacy error.
import cv2
img = cv2.imread('lena.jpg', 1)
print(img)
cv2.imshow('image', img)
cv2.waitKey(10000)
cv2.destroyAllWindows()
My error:
Traceback (most recent call last):
File "/Users/mac/myprojects/opencv/read_and_display_image.py", line 1, in
import cv2
File "/Users/mac/myprojects/opencv/openenv/lib/python3.9/site-packages/cv2/init.py", line 181, in
bootstrap()
File "/Users/mac/myprojects/opencv/openenv/lib/python3.9/site-packages/cv2/init.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: dlopen(/Users/mac/myprojects/opencv/openenv/lib/python3.9/site-packages/cv2/cv2.abi3.so, 2): Symbol not found: _VTRegisterSupplementalVideoDecoderIfAvailable
Referenced from: /Users/mac/myprojects/opencv/openenv/lib/python3.9/site-packages/cv2/.dylibs/libavcodec.59.37.100.dylib
Expected in: /System/Library/Frameworks/VideoToolbox.framework/Versions/A/VideoToolbox
in /Users/mac/myprojects/opencv/openenv/lib/python3.9/site-packages/cv2/.dylibs/libavcodec.59.37.100.dylib

Related

Console problem in Spyder showing: an error ocurred while starting the kernel [duplicate]

Spyder console is showing an error msg:
An error ocurred while starting the kernel
Traceback (most recent call last): File "C:\Users\ABCD\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "C:\Users\ABCD\Anaconda3\lib\runpy.py",
line 85, in _run_code exec(code, run_globals) File "C:\Users\ABCD\Anaconda3\lib\site‑packages\spyder_kernels\console\__main__.py",
line 11, in start.main() File "C:\Users\ABCD\Anaconda3\lib\site‑packages\spyder_kernels\console\start.py",
line 287, in main import_spydercustomize() File "C:\Users\ABCD\Anaconda3\lib\site‑packages\spyder_kernels\console\start.py",
line 39, in import_spydercustomize import spydercustomize File "C:\Users\ABCD\Anaconda3\lib\site‑packages\spyder_kernels\customize\spydercustomize.py",
line 27, in from IPython.core.getipython import get_ipython File "C:\Users\ABCD\Anaconda3\lib\site‑packages\IPython\__init__.py",
line 55, in from .terminal.embed import embed File "C:\Users\ABCD\Anaconda3\lib\site‑packages\IPython\terminal\embed.py",
line 17, in from IPython.terminal.ipapp import load_default_config File "C:\Users\ABCD\Anaconda3\lib\site‑packages\IPython\terminal\ipapp.py",
line 28, in from IPython.core.magics import ( File "C:\Users\ABCD\Anaconda3\lib\site‑packages\IPython\core\magics\__init__.py",
line 18, in from .code import CodeMagics, MacroToEdit File "C:\Users\ABCD\Anaconda3\lib\site‑packages\IPython\core\magics\code.py",
line 23, in from urllib.request import urlopen File "C:\Users\ABCD\Anaconda3\lib\urllib\request.py",
line 86, in import email File "C:\Users\ABCD\email.py",
line 8, in n=input() EOFError: EOF when reading a line
What I understood on reading other threads about similar kind of problems , that this is due to having two python versions installed
So, I tried manually removing all python files (as I was unable to uninstall python) and then uninstalled and reinstalled anaconda (spyder) but the problem persists
Any kind of help wd be appreciated
Short answer: To fix this problem, you need to remove or rename this file:
C:\Users\ABCD\email.py
Long answer: That file has the same name of a core Python module. Since it's placed in your home directory, it has higher priority than that module, which makes Python to use it first and ends up causing the error.

ImportError during python run

Currently I am executing doamusic python codes from
https://github.com/yump/doamusic.git
I am using python 3.7.2. (Python IDLE) on windows.
My directory tree is
F:\doamusic_project\doamusic\music.py
when I run music.py, I am getting the following error
Traceback (most recent call last):
File "F:\doamusic_project\doamusic\music.py", line 31, in
from . import util
File "..\doamusic__init__.py", line 1, in
from doamusic.music import *
File "..\doamusic\music.py", line 32, in
from . import _music
ImportError: cannot import name '_music' from 'doamusic' (..\doamusic__init__.py)
What is the reason for not importing _music ?.
You are trying to do an import from .pyx file. A .pyx file must be compiled unlike a .py file.
Try to do that before the import of _music:
import pyximport
pyximport.install()
More info Cython

Unable to run tune_blockmatcher and image_to_pointcloud programs

I am able to capture images on webcams and calibrate them well using
StereoVision library from erget.
But, while trying for execution of tune_blockmatcher and images_to_pointcloud, i found below errors as StereoBM and StereoSGBM classes are unable to import.
>import cv2
>from stereovision.blockmatchers import StereoBM, StereoSGBM
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\stereovision\blockmatchers.py", line 111,
in <module>
class StereoBM(BlockMatcher):
File "C:\Python27\lib\site-packages\stereovision\blockmatchers.py", line 117,
in StereoBM
"stereo_bm_preset": cv2.STEREO_BM_NARROW_PRESET}
AttributeError: 'module' object has no attribute 'STEREO_BM_NARROW_PRESET'
>`
C:\s\StereoVision-master\stereovision>python tune_blockmatcher.py
Traceback (most recent call last):
File "tune_blockmatcher.py", line 34, in <module>
from stereovision.blockmatchers import StereoBM, StereoSGBM
File "build\bdist.win-amd64\egg\stereovision\blockmatchers.py", line 111, in <
module>
class StereoBM(BlockMatcher):
File "build\bdist.win-amd64\egg\stereovision\blockmatchers.py", line 117, in S
tereoBM
"stereo_bm_preset": cv2.STEREO_BM_NARROW_PRESET}
AttributeError: 'module' object has no attribute 'STEREO_BM_NARROW_PRESET'
OS i am running is Windows7, running OPENCV 3.4.0 and Python2.7, installed stereovision library with 'pip install StereoVision'
Any solution for this issue ?
You are facing this issue because the StereoVision framework provided by Daniel Lee does not work with OpenCV 3.
First of all, uninstall OpenCV 3 from your machine.
Then install OpenCV 2 and retry: your problem will be gone.
Hope this helps

How to solve CUDA PATH Error?

I recently installed NVIDIA CUDA and test run a code :
from numba import cuda
from numba import *
import numpy as np
from pylab import imshow, show
from timeit import default_timer as timer
But I got this error in ubuntu 16.0.4. How can I resolve this error:
#cuda.jit(argtypes=[f8, f8, f8, f8, uint8[:,:], uint32])
File "/usr/local/lib/python2.7/dist-packages/numba/cuda/decorators.py", line 92, in kernel_jit
kernel.bind()
File "/usr/local/lib/python2.7/dist-packages/numba/cuda/compiler.py", line 489, in bind
self._func.get()
File "/usr/local/lib/python2.7/dist-packages/numba/cuda/compiler.py", line 366, in get
cuctx = get_context()
File "/usr/local/lib/python2.7/dist-packages/numba/cuda/cudadrv/devices.py", line 194, in get_context
return _runtime.get_or_create_context(devnum)
File "/usr/local/lib/python2.7/dist-packages/numba/cuda/cudadrv/devices.py", line 162, in get_or_create_context
return self.push_context(self.gpus[devnum])
File "/usr/local/lib/python2.7/dist-packages/numba/cuda/cudadrv/devices.py", line 40, in __getitem__
return self.lst[devnum]
File "/usr/local/lib/python2.7/dist-packages/numba/cuda/cudadrv/devices.py", line 26, in __getattr__
numdev = driver.get_device_count()
File "/usr/local/lib/python2.7/dist-packages/numba/cuda/cudadrv/driver.py", line 307, in get_device_count
self.cuDeviceGetCount(byref(count))
File "/usr/local/lib/python2.7/dist-packages/numba/cuda/cudadrv/driver.py", line 248, in __getattr__
self.initialization_error)
CudaSupportError: Error at driver init:
CUDA driver library cannot be found.
If you are sure that a CUDA driver is installed,
try setting environment variable NUMBA_CUDA_DRIVER
with the file path of the CUDA driver shared library.
Try to introduce following variables
export NUMBAPRO_NVVM=/home/cuda-7.5/nvvm/lib64/libnvvm.so
export NUMBAPRO_LIBDEVICE=/home/cuda-7.5/nvvm/libdevice/
in your .bashrc file which is usually located in home/username/
In your case the paths above should be corrected in accordance to your cuda installation paths. Note, that even if you use just umba, not numbapro the names of the variables should be as shown above.

Unable to compile third-party package for iOS using Kivy toolchain

I am working on a small testing project and wanted to add Robot Remoteserver onto an iOS device but can't get toolchain to build the package successfully. Here's the errors I get when I attempt to build this package:
copying build/lib/robotremoteserver.py -> /Users/usman/kivy/kivy-ios/build/robotremoteserver/i386/PythonRemoteServer-master/iosbuild/lib/python2.7/site-packages
byte-compiling /Users/usman/kivy/kivy-ios/build/robotremoteserver/i386/PythonRemoteServer-master/iosbuild/lib/python2.7/site-packages/robotremoteserver.py to robotremoteserver.pyc
writing byte-compilation script '/tmp/tmpM9XgVf.py'
/Users/usman/kivy/kivy-ios/dist/hostpython/bin/python -OO /tmp/tmpM9XgVf.py
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
removing /tmp/tmpM9XgVf.py
running install_egg_info
Removing /Users/usman/kivy/kivy-ios/build/robotremoteserver/i386/PythonRemoteServer-master/iosbuild/lib/python2.7/site-packages/robotremoteserver-devel-py2.7.egg-info
Writing /Users/usman/kivy/kivy-ios/build/robotremoteserver/i386/PythonRemoteServer-master/iosbuild/lib/python2.7/site-packages/robotremoteserver-devel-py2.7.egg-info
Traceback (most recent call last):
File "./toolchain.py", line 1224, in <module>
ToolchainCL()
File "./toolchain.py", line 1040, in __init__
getattr(self, args.command)()
File "./toolchain.py", line 1064, in build
build_recipes(args.recipe, ctx)
File "./toolchain.py", line 933, in build_recipes
recipe.execute()
File "/Users/usman/kivy/kivy-ios/toolchain.py", line 556, in execute
self.build_all()
File "/Users/usman/kivy/kivy-ios/toolchain.py", line 56, in _cache_execution
f(self, *args, **kwargs)
File "/Users/usman/kivy/kivy-ios/toolchain.py", line 668, in build_all
self.install()
File "/Users/usman/kivy/kivy-ios/toolchain.py", line 56, in _cache_execution
f(self, *args, **kwargs)
File "/Users/usman/kivy/kivy-ios/toolchain.py", line 794, in install
self.install_python_package()
File "/Users/usman/kivy/kivy-ios/toolchain.py", line 835, in install_python_package
dest_dir)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 171, in copytree
names = os.listdir(src)
OSError: [Errno 2] No such file or directory: '/Users/usman/kivy/kivy-ios/build/robotremoteserver/i386/PythonRemoteServer-master/iosbuild/lib/python2.7/site-packages/robotremoteserver'
For the line Could not find platform dependent libraries I did set the PYTHONPATH but still had this error.
Since there's no template to follow for the build script, I viewed the build files for the packages kivy comes with and created one that contains the following
from toolchain import PythonRecipe
class RobotRemoteServer(PythonRecipe):
version = "master"
url = "https://github.com/robotframework/PythonRemoteServer/archive/{version}.zip"
depends = ["python"]
recipe = RobotRemoteServer()
I have ensured Kivy and the packages it depends on are all installed correctly. I've also searched the web but can't quite figure out what the problem is. I'm using Xcode 6.4 and latest kivy pull from git. I have been stuck on this for a few days and appreciate any help or guidance.
Kivy recipes follow the same format as those for python-for-android. Here you have the related documentation.

Resources