This will get you up and running with OpenCV and Python 3 on a development laptop. You should be relatively comfortable with running commands and changing directories, setting permissions for files and folders from the command line.
- Launch the terminal and change directory to you home directory.
- Create a work directory if one doesn't already exist.
- Change directory to your work directory and launch the Atom editor:
atom . - Create
show_img.pyand write a program to open and display an image file you supply as an argument to the script.
#!/usr/bin/env python3
import cv2
import os.path
import sys
imgPath = sys.argv[1]
if not os.path.isfile(imgPath):
print("usage: show_img.py <file>")
sys.exit()
img = cv2.imread(imgPath)
cv2.imshow('image', img)
cv2.waitKey(0)- Back in the terminal, run you new script in Python 3.
~/exercises $ python3 show_img.py- Make the script executable and run it directly from the command line.
~/exercises $ chmod +x show_img.py
~/exercises $ ./show_img.pyThis will get you up and running with OpenCV and C++ on a development laptop. You should be relatively comfortable with running commands and changing directories, setting permissions for files and folders from the command line.
- Launch the terminal and change directory to you home directory.
- Create a work directory if one doesn't already exist.
- Change directory to your work directory and launch the Atom editor:
atom . - Create
show_img.cpp.
#include <opencv2/highgui/highgui.hpp>
int main() {
cv::Mat img = cv::imread("trex.png");
cv::imshow("Tyrannosaurus Rex", img);
cv::waitKey();
}
- Back in the terminal, compile and run your program. In this example we use
make.
$ make
$ ./show_img