Skip to content

Latest commit

 

History

History
100 lines (69 loc) · 3.08 KB

File metadata and controls

100 lines (69 loc) · 3.08 KB

OpenCV Learning Path

OpenCV and Python

Set up an OpenCV and Python 3 development environment

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.

Tasks

  1. Launch the terminal and change directory to you home directory.
  2. Create a work directory if one doesn't already exist.
  3. Change directory to your work directory and launch the Atom editor: atom .
  4. Create show_img.py and 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)
  1. Back in the terminal, run you new script in Python 3.
~/exercises $ python3 show_img.py
  1. Make the script executable and run it directly from the command line.
~/exercises $ chmod +x show_img.py
~/exercises $ ./show_img.py

Example

References

OpenCV and C++

Set up an OpenCV and C++ development environment

This 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.

Tasks

  1. Launch the terminal and change directory to you home directory.
  2. Create a work directory if one doesn't already exist.
  3. Change directory to your work directory and launch the Atom editor: atom .
  4. 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();
}
  1. Back in the terminal, compile and run your program. In this example we use make.
$ make
$ ./show_img

Example

References