installing OpenCV on centos 8 - linux

I'm trying to install opencv on my centos8 server and use it in my java program. I followed the instructions mentioned here, but when I change directory to /opencv/build folder and run
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 ..
,I get the following error:
CMake Error: The source directory "/root/opencv_build" does not appear to contain CMakeLists.txt.
how to solve this issue? the solutions here didn't help.

Related

Error while trying to install Kops on Ubuntu 20 EC2 Instance

I went through the steps listed here: https://kubernetes.io/docs/setup/production-environment/tools/kops/
After moving the kops file to /usr/local/bin/ and renaming to kops, I tried to confirm if it was in fact installed and executable by trying 'kops --help' and 'kops --version'/'kops version' and neither command worked. Any idea what the issue might be?
Edit: Here's what I did step by step
curl -LO https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-darwin-amd64
sudo chmod +x kops-darwin-amd64
sudo mv kops-darwin-amd64 /usr/local/bin/kops
It's a t2.micro Ubuntu 20.04 EC2 Instance.
Tried to confirm if kops was properly installed and executable by entering 'kops --help' and 'kops --version' and also 'kops version' but they all return this error:
-bash: /usr/local/bin/kops: cannot execute binary file: Exec format error
I think its because you are using kops-darwin-amd64. This is for mac. I think you should be using kops-linux-amd64 instead for linux.

Execution CMake from within a Bash Script

I've built a script to automate a CMake build of OpenCV4. The relevant part of the script is written as:
install.sh
#!/bin/bash
#...
cd /home/pi/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D BUILD_TESTS=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=OFF ..
This part of the code is first executed from /home/pi/ directory. If I execute these lines within the cli they work and the cmake file is built without error. If I run this same code form a bash script it results in the cmake command resulting in -- Configuring incomplete, errors occurred!.
I believe this is similar to these two SO threads (here and here) in as much as they both describe situations where calling a secondary script from the first script creates a problem (or at least that's what I think they are saying). If that is the case, how can you start a script from /parent/, change to /child/ within the script, execute secondary script (CMake) as though executed from the /child/ directory?
If I've missed my actual problem - highlighting taht would be even more helpful.
Update with Full Logs
Output log for CMakeOutput.log and CMakeError.log as unsuccessfully run from the bash script.
When executed from the cli the successful logs are success_CMakeOutput.log and success_CMakeError.log
Update on StdOut
I looked through the files above and they look the same... Here is the failed screen output (noting the bottom lines) and the successful screen output.
You are running your script as the root user with the /root home directory, while the opencv_contrib directory is in /home/pi directory. The /home/pi is most probably the home directory of the user pi.
Update the:
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
With proper path to opencv_contrib. Either provide opencv_contrib in the home directory of the root user, if you aim to run the script as root, or provide full, non-dependent on HOME, path to opencv_contrib directory.
-D OPENCV_EXTRA_MODULES_PATH=/home/pi/opencv_contrib/modules \

Bad Substitution Error Installing NVM within Debian-based Docker image

I am trying to install nvm on my Docker image. I originally thought that this Docker image was built on Ubuntu, but it is actually built on Debian. I am installing bash to curl NVM, and subsequently install node, but I get a bad substitution error:
Here's my Dockerfile:
FROM docker
RUN apk add --update bash \
&& touch /root/.bashrc \
&& curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.2/install.sh | bash \
&& source /root/.bashrc \
&& nvm install node \
&& npm install
I think the following error has to do with the line && source /root/.bashrc \
=> Downloading nvm as script to '/root/.nvm'
0
=> Appending source string to /root/.bashrc
=> Close and reopen your terminal to start using nvm
/bin/sh: /root/.nvm/nvm.sh: line 107: syntax error: bad substitution
ERROR: Service 'docker' failed to build: The command '/bin/sh -c apk add --update bash && touch /root/.bashrc && curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.2/install.sh | bash && source /root/.bashrc && nvm install node && npm install' returned a non-zero code: 2
Do you see what is causing this bad substitution error, and is there a more simple way to install nvm on a Debian based Docker image? Thanks for any help.
Docker image is based out of Alpine Linux. Alpine Linux uses the default shell as sh. The error is because of the sh vs bash incompatibilities.
Unfortunately, NVM home page has instructions about Alpine Linux, but quite discouraging:
nvm on Alpine Linux
After some changes, the final version that made nvm work with Alpine:
FROM docker
RUN apk add --update bash coreutils ncurses tar gzip nodejs \
&& touch ~/.bashrc \
&& curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.2/install.sh | sh \
&& LINE=$(cat /root/.nvm/nvm.sh | grep -in '{BASH_SOURCE\[0\]}' | awk -F: '{print $1}') \
&& sed -i "${LINE}s/BASH_SOURCE\[0\]\}/BASH_SOURCE\}\$\{0\}/" /root/.nvm/nvm.sh \
&& source ~/.bashrc \
&& nvm ls \
&& nvm install node \
&& nvm use --delete-prefix v6.3.1 \
&& npm install
A little inconvenience being, you need to use the nvm use --delete-prefix v6.3.1 every time you need to work with it.
I suggest to try #BMitch's updated answer as well.
FROM docker bases your image on the "Docker in Docker" Alpine image. Unless you have a special use case that requires Docker in Docker, this probably isn't the base image you want.
If you want a node image, consider using the premade node image. This is based on Debian jessie.
If you need to base your node install another version of Debian or Ubuntu, you can pick from multiple versions of those images, e.g. FROM debian:jessie.
Edit: it's pretty easy to add Docker to another image. Here are my Dockerfile entries for a Debian based image (appuser is a user added elsewhere that the container would normally run as, hence the Docker group addition):
ARG DOCKER_GID=999
USER root
RUN curl -sSL https://get.docker.com/ | sh
RUN groupmod -g ${DOCKER_GID} docker && \
usermod -aG docker appuser

Error Loading Shared Library (glew)

I compiled the library GLEW. It seemed to work fine, here is the output of make install:
install -d -m 0755 "/usr/include/GL"
install -m 0644 include/GL/wglew.h "/usr/include/GL/"
install -m 0644 include/GL/glew.h "/usr/include/GL/"
install -m 0644 include/GL/glxew.h "/usr/include/GL/"
sed \
-e "s|#prefix#|/usr|g" \
-e "s|#libdir#|/usr/lib64|g" \
-e "s|#exec_prefix#|/usr/bin|g" \
-e "s|#includedir#|/usr/include/GL|g" \
-e "s|#version#|1.11.0|g" \
-e "s|#cflags#||g" \
-e "s|#libname#|GLEW|g" \
-e "s|#requireslib#|glu|g" \
< glew.pc.in > glew.pc
install -d -m 0755 "/usr/lib64"
install -m 0644 lib/libGLEW.so.1.11.0 "/usr/lib64/"
ln -sf libGLEW.so.1.11.0 "/usr/lib64/libGLEW.so.1.11"
ln -sf libGLEW.so.1.11.0 "/usr/lib64/libGLEW.so"
install -m 0644 lib/libGLEW.a "/usr/lib64/"
install -d -m 0755 "/usr/lib64"
install -d -m 0755 "/usr/lib64/pkgconfig"
install -m 0644 glew.pc "/usr/lib64/pkgconfig/"
Now I wanted to use it on a KDevelop project. I created my CMakeLists.txt and linked the library there using find_package:
cmake_minimum_required( VERSION 2.6 )
project(openglengine)
include_directories(headers)
set(SOURCE_FILES src/main.cpp)
set(CMAKE_CXX_FLAGS "--pedantic-errors -Wall -std=gnu++11")
add_executable(openglengine ${SOURCE_FILES} ${HEADER_FILES})
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
target_link_libraries(openglengine ${GLFW_STATIC_LIBRARIES})
find_package(GLEW)
if (GLEW_FOUND)
include_directories(${GLEW_INCLUDE_DIRS})
target_link_libraries (openglengine ${GLEW_LIBRARIES})
endif (GLEW_FOUND)
install(TARGETS openglengine RUNTIME DESTINATION ~/projects/OpenGLEngine/bin)
I get no build errors.
When I try to run the program here is the output:
error while loading shared libraries: libGLEW.so.1.11: cannot open shared object file: No such file or directory
Any help will be appreciated.
EDIT:
Using the command locate libGLEW I get this output:
/home/lhahn/.local/share/Steam/ubuntu12_32/steam-runtime/amd64/usr/lib/x86_64-linux-gnu/libGLEW.so.1.10
/home/lhahn/.local/share/Steam/ubuntu12_32/steam-runtime/amd64/usr/lib/x86_64-linux-gnu/libGLEW.so.1.10.0
/home/lhahn/.local/share/Steam/ubuntu12_32/steam-runtime/amd64/usr/lib/x86_64-linux-gnu/libGLEW.so.1.6
/home/lhahn/.local/share/Steam/ubuntu12_32/steam-runtime/amd64/usr/lib/x86_64-linux-gnu/libGLEW.so.1.6.0
/home/lhahn/.local/share/Steam/ubuntu12_32/steam-runtime/i386/usr/lib/i386-linux-gnu/libGLEW.so.1.10
/home/lhahn/.local/share/Steam/ubuntu12_32/steam-runtime/i386/usr/lib/i386-linux-gnu/libGLEW.so.1.10.0
/home/lhahn/.local/share/Steam/ubuntu12_32/steam-runtime/i386/usr/lib/i386-linux-gnu/libGLEW.so.1.6
/home/lhahn/.local/share/Steam/ubuntu12_32/steam-runtime/i386/usr/lib/i386-linux-gnu/libGLEW.so.1.6.0
/home/lhahn/.local/share/Trash/files/glew/lib/libGLEW.a
/home/lhahn/.local/share/Trash/files/glew/lib/libGLEW.so
/home/lhahn/.local/share/Trash/files/glew/lib/libGLEW.so.1.11
/home/lhahn/.local/share/Trash/files/glew/lib/libGLEW.so.1.11.0
/home/lhahn/.local/share/Trash/files/glew/lib/libGLEWmx.a
/home/lhahn/.local/share/Trash/files/glew/lib/libGLEWmx.so
/home/lhahn/.local/share/Trash/files/glew/lib/libGLEWmx.so.1.11
/home/lhahn/.local/share/Trash/files/glew/lib/libGLEWmx.so.1.11.0
/home/lhahn/Documents/OpenGL-Utils/GLEW/glew-1.11.0/lib/libGLEW.a
/home/lhahn/Documents/OpenGL-Utils/GLEW/glew-1.11.0/lib/libGLEW.so
/home/lhahn/Documents/OpenGL-Utils/GLEW/glew-1.11.0/lib/libGLEW.so.1.11
/home/lhahn/Documents/OpenGL-Utils/GLEW/glew-1.11.0/lib/libGLEW.so.1.11.0
/home/lhahn/Documents/OpenGL-Utils/GLEW/glew-1.11.0/lib/libGLEWmx.a
/home/lhahn/Documents/OpenGL-Utils/GLEW/glew-1.11.0/lib/libGLEWmx.so
/home/lhahn/Documents/OpenGL-Utils/GLEW/glew-1.11.0/lib/libGLEWmx.so.1.11
/home/lhahn/Documents/OpenGL-Utils/GLEW/glew-1.11.0/lib/libGLEWmx.so.1.11.0
/usr/lib64/libGLEW.a
/usr/lib64/libGLEW.so
/usr/lib64/libGLEW.so.1.11
/usr/lib64/libGLEW.so.1.11.0
Which show that I have the library. Does that mean that the command find_package may be not working? Which is strange because I get no link errors.
So, I managed to make it work by creating a symbolic link in /usr/lib/ for the library that was in /usr/lib64.
sudo ln -s /usr/lib64/libGLEW.so.1.11 /usr/lib/libGLEW.so.1.11
Now it works fine. Since I am no expert on linux I don't know if that will bring me problems in the future.
I don't know if the answer by #Ihahn will have any issues but, if the some program is not finding your shared libraries, then first find the folder that your library was installed and is not in your shared library folder and then run sudo ldconfig <location_where_your_library_or_program_was_installed>. Sometimes this happens when you're installing/building programs via make install.Reference here..

Cross compiling and CMake?

I'm building an embedded Linux system for ARM, and one of the applications is using CMake:
cmake \
-D CMAKE_C_COMPILER=/opt/arm-toolchain/bin/arm-linux-gnueabihf-gcc \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_SYSTEM_NAME=Linux \
-D CMAKE_INSTALL_PREFIX=/mnt/system_rootfs ../app_src_dir
If CMake is executed like this, it searches the whole file system for libraries, header files etc.
How can I restrict CMake to ONLY search /opt/arm-toolchain and /mnt/system_rootfs for header files, libraries and programs?
Build system is Debian Wheezy and CMake version is 2.8.9
You can use CMAKE_INCLUDE_PATH and CMAKE_LIBRARY_PATH environment variable for searching header files, libraries.
cmake \
-D CMAKE_C_COMPILER=/opt/arm-toolchain/bin/arm-linux-gnueabihf-gcc \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_SYSTEM_NAME=Linux \
-D CMAKE_INSTALL_PREFIX=/mnt/system_rootfs ../app_src_dir
-D CMAKE_INCLUDE_PATH=/include/path
-D CMAKE_LIBRARY_PATH=/lib/path/

Resources