importing python opencv library into sikuliX - opencv

I am trying to import the opencv library into sikuliX which uses Jython interpreter.
I have added the path where cv2 module is installed to sys.path.append to tell Jython to look for cv2 folder in the path supplied.
import sys
sys.path.append("/Users/ongyichong/anaconda3/lib/python3.7/site-
packages/")
import cv2
I installed opencv using pip install opencv-contrib-lib and the path where cv2 is installed in the path "/Users/ongyichong/anaconda3/lib/python3.7/site-packages/".
This is what my cv2 folder looks like.
The error arises because my init.py file contains a ".cv2 import *". I am not sure how i should go about solving this problem. Is there another way i can import python modules into SikuliX's Jython interpreter ?

Python (C-Python) modules can only be used in SikuliX (Jython interpreter) when they are completely written in Python language and do not contain any C-based stuff or even reference native libraries.
BTW: especially since SikuliX 1.1.4 the complete OpenCV 3 API is available at the Java level, which is also accessible from the Jython scripting level.

Related

Linking ROS Noetic to opencv build from source

I am writing a ROS node which uses OpenCV and SIFT (ROS Noetic, Ubuntu 20.04).
As of OpenCV version 4, the SIFT algorithm is part of the opencv_contrib package.
Within my ROS node, I want to use the ROS package cv_bridge, to convert between the OpenCV image format and ROS image sensor messages.
My understanding is that
Code in the opencv_contrib package is only usable if such package is built together with OpenCV from source.
cv_bridge depends on the Ubuntu package version of OpenCV, libopencv-dev.
I currently have both installed (the Ubuntu package and the version compiled from source) and I am trying to have my node depend on the source-compiled one, in order to use the non-free algorithms.
My procedure in order to do this is (after compiling OpenCV with the additional modules and OPENCV_ENABLE_NONFREE=ON) adding to the CMakeLists.txt of my package the following lines:
find_package(OpenCV PATHS .../opencv-4.5.4/cmake)
include_directories(include ${catkin_INCLUDE_DIRS} .../opencv-4.5.4/include)
link_directories(.../opencv-4.5.4/lib)
add_executable(...)
target_link_libraries(nodeName ${catkin_LIBRARIES} .../opencv-4.5.4/lib)
in order to link my code to the compiled version of OpenCV. However, when I try to build it with catkin build I obtain:
In file included from [...]:
[...]/markerDetection.h:8:10: fatal error: opencv2/xfeatures2d.hpp: No such file or directory
8 | #include <opencv2/xfeatures2d.hpp>
I suspect that ROS is trying to link to the version I installed through the package manager, which in fact does not have the opencv2/xfeatures2d.hpp library.
Am I setting the wrong options in CMakeLists.txt? Is what I am trying to do even possible?

How to point to new install Opencv with PythonPath?

After installing and building opencv 4.0 with this script, I import opencv with python and checked the version. It prints 3.2.0 instead of 4.0.0
I also found a few others with the same problem here. The answer is to export PYTHONPATH=$PYTHONPATH:${OpenCV DIR}/release/python
I'm not to familiar with using Python paths but I assume the correct statement to use is export PYTHONPATH=$PYTHONPATH:${opencv-4.0.0}/release/python_loader and reload bashrc. Is this the right way to load the recently installed opencv for python?
Here is what my directory looks like
https://i.imgur.com/z3nBd9S.png
export PYTHONPATH=~/opencv/opencv-4.0.0/release/lib/python3

install package using pip (version confused)

I think since I'm new to python, I installed packages in multiple subversion. like python 2.7.15 or python 2.7.14.
If I import certain package (e.g., hdf5storage) using terminal (python 2.7.15), I can >> import hdf5storage
but if I import the package using jupyter notebook (python 2.7.14), i cannot. >> import hdf5storage
no module called hdf5storage.
I didn't install this different version on purpose, it just happened.
I used pip2 to install packages. Can anyone explain how to solve this issue, for a beginner? How do I use virtualenv or edit PATH, it's very confusing for me. Any answer would be appreciated!

ImportError: No module named 'cv2' on Watson Studio

The command
import cv2
on Watson Studio results in the error
ImportError Traceback (most recent call last)<ipython-input-1-72fbbcfe2587> in <module>()----> 1 import cv2
ImportError: No module named 'cv2'
I'm not sure if I need to install opencv upfront and how to do this in a cloud environment like Watson Studio?
cv2 is part of opencv-python package.
Please install the pypi hosted libararies using !pip magic in jupyter notebook.
!pip install opencv-python
Then run the import cv2.
See this shared notebook
https://dataplatform.ibm.com/analytics/notebooks/v2/a0e50c53-ea28-4b78-800f-35cae2211389/view?access_token=b129fa46626e1bf317de18c9241af375d9a9ac8e11561e3735569050fe0b8839
Also see this documentation for installing third party libraries.
https://datascience.ibm.com/docs/content/analyze-data/importing-libraries.html

When i import parse in ipython , computer say 'parse' it not defined

I think i don't have parse library. So, Where can i get it?
As beginner, I need your help.
I wrote from lxml.html import parse , Computer say name 'parse' is not defined
You actually probably need the lxml package, which was in the comment by cel. It seems to me like your question is concerning how to actually install the package. Everything at PyPi (the Python package index) can be installed in several ways. For me, the easiest is using pip, which is a tool for installing Python packages. Here are some links for how to get pip on your machine for different operating systems: Windows, Mac OSX, or in general.
Once you have pip installed, you go to your command line and type
pip install ['package_name']
where, in your case, package_name would be lxml. Once you do that, your import should work just fine. The full pip documentation is here.
If you prefer to manually install the package, you can download the source and install it according to the Python docs for Python 2.x or 3.x.

Resources