<jupyter_start><jupyter_text>OpenCV Tutorial Sample_01: ocv_info[Sample 01](ocv_info.py) is a simple diagnostic program that queries the development environment and ensures that all the prerequisites have been met and displays the version information. It also checks to see if Environment variables have been set and displays the path for diagnostics if necessary.>*Note:* If you are using pre-built OpenCV, you need to use Python 2.7.x to run the samples. If you have built OpenCV from source, then you can use either Python 3.x or Python 2.x.First the Standard Python Shebang<jupyter_code>#!/usr/bin/env python2<jupyter_output><empty_output><jupyter_text>Next import print_function for Python 2/3 comptibility. This allows use of print like a function in Python 2.x<jupyter_code>from __future__ import print_function<jupyter_output><empty_output><jupyter_text>OpenCV uses Numpy arrays to manipulate image and video data and is a mandatory requirement. So import numpy module first.<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>Now print the version. In the script this is done at the end in the Program Outputs block<jupyter_code>print('Numpy Version:', np.__version__)<jupyter_output>Numpy Version: 1.12.1<jupyter_text>Next import the OpenCV python module<jupyter_code>import cv2<jupyter_output><empty_output><jupyter_text>Now print the version. In the script this is done at the end in the Program Outputs block<jupyter_code>print('OpenCV Version:', cv2.__version__)<jupyter_output>OpenCV Version: 3.2.0<jupyter_text>Import the other required python modules for this script. Matplotlib is used in a number of tutorials found in the OpenCV package and OS and sys are needed to test whether the OpenCV environment variables are properly setup.<jupyter_code>import matplotlib as mpl
import os
import sys<jupyter_output><empty_output><jupyter_text>Now print the versions here. In the script this is done at the end in the Program Outputs block<jupyter_code>print('Matplotlib Version:', mpl.__version__)
print(sys.version)<jupyter_output>Matplotlib Version: 2.0.1
2.7.13 |Anaconda custom (32-bit)| (default, Dec 19 2016, 13:36:02) [MSC v.1500 32 bit (Intel)]<jupyter_text>Now we check to see if the OpenCV environment variables have been properly set. We need to do this in a safe way to prevent the script from crashing in case no variable has been set. So use standard python exception handling...<jupyter_code>try:
    pyth_path = os.environ['PYTHONPATH'].split(os.pathsep)
except KeyError:
    pyth_path = []<jupyter_output><empty_output><jupyter_text>Now print the environment variable. In the script this is done at the end in the Program Outputs block.<jupyter_code>print('Python Environment Variable - PYTHONPATH:', pyth_path)<jupyter_output>Python Environment Variable - PYTHONPATH: ['C:\\Users\\vinay\\Anaconda2\\Library\\bin']<jupyter_text>Next check the OpenCV environemnt variables<jupyter_code>try:
    ocv2_path = os.environ['OPENCV_DIR']
except KeyError:
    ocv2_path = []
    
try:
    ocv2_vers = os.environ['OPENCV_VER']
except KeyError:
    ocv2_path = []<jupyter_output><empty_output><jupyter_text>Now print the environment variable. In the script this is done at the end in the Program Outputs block<jupyter_code>print('OpenCV Environment Variable - OPENCV_DIR:', ocv2_path)
print('OpenCV Environment Variable - OPENCV_VER:', ocv2_vers)<jupyter_output>OpenCV Environment Variable - OPENCV_DIR: C:\opencv_pre\
OpenCV Environment Variable - OPENCV_VER: 320<jupyter_text>Finally check the FFMPEG environment variable<jupyter_code>try:
    ffmp_path = os.environ['FFMPEG_BIN']
except KeyError:
    ffmp_path = []<jupyter_output><empty_output><jupyter_text>Now print the environment variable. In the script this is done at the end in the Program Outputs block<jupyter_code>print('FFMPEG Environment Variable - FFMPEG_BIN:', ffmp_path)<jupyter_output>FFMPEG Environment Variable - FFMPEG_BIN: C:\opencv_pre\build\bin
{'fraction_non_alphanumeric': 0.0767289247854619, 'fraction_numerical': 0.01463907117617365, 'mean_word_length': 6.218579234972678, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '482734', 'license': 'MIT', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1229, 'n_words': 420, 'path': 'tutorials/opencv/Python/sample_01_info/ocv_info.ipynb', 'repo_name': 'intel-iot-devkit/Intel-Digital-Signage-Reference', 'size': '3962'}