Metadata-Version: 2.4
Name: python-opencv2
Version: 1.0.0
Summary: Offline library of image processing and machine learning lab programs with algorithms, flow charts and ready-to-run Python code
License: MIT
Keywords: opencv,image-processing,knn,linear-regression,lab,education
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: numpy
Requires-Dist: matplotlib
Requires-Dist: opencv-python
Requires-Dist: scikit-learn

# python-opencv2

An offline Python package that contains 11 lab programs, each with its question, algorithm, flow chart
and a ready-to-run, comment-free Python solution. Ask for the program you want and get its code.

| No | Tag | Program |
|----|-----|---------|
| 1 | IP1 | Read color image, convert to grayscale, histogram with and without function |
| 2 | IP2 | Separation of R, G, B channels |
| 3 | IP3 | Determine whether an image is color, grayscale or binary |
| 4 | IP4 | Histogram equalization with and without function |
| 5 | IP5 | Mean filter with and without function |
| 6 | IP6 | Median filter with and without function |
| 7 | IP7 | Sobel edge detection without function |
| 8 | IP8 | Canny edge detection without function |
| 9 | ML1 | Binary KNN classifier with and without function |
| 10 | ML2 | Multiclass KNN classifier with and without function |
| 11 | ML3 | Linear regression with and without function |

"Without function" means the algorithm is written by hand with NumPy. "With function" means the library
routine is used (OpenCV for the image programs, scikit-learn for the machine learning programs).

## Install

```
pip install .
```

The package needs no internet at run time. Install its four dependencies once (numpy, matplotlib,
opencv-python, scikit-learn); if they are already installed, `pip install --no-deps .` is enough.

## Command line

```
python-opencv2                      interactive menu: pick a program, view it, save it, run it
python-opencv2 list                 table of all programs
python-opencv2 code 7               only the code of program 7 (add > sobel.py to save it)
python-opencv2 code sobel           same, found by keyword
python-opencv2 code "multiclass knn"
python-opencv2 show IP4             question, algorithm, flow chart and code
python-opencv2 algo ML3             only the algorithm
python-opencv2 flow canny           only the flow chart
python-opencv2 question 5           only the question text
python-opencv2 save 8 -o canny.py   write the program to a file
python-opencv2 run 4 -i photo.jpg   run the program on your own image
python-opencv2 run knn binary       run an ML program (no image needed)
python-opencv2 export my_lab        write all programs, algorithms and flow charts into a folder
```

A program can be chosen by its number (1-11), its tag (IP1-IP8, ML1-ML3) or by words. If the words match
more than one program, the matches are listed so that you can be more specific.

## Python API

```python
import python_opencv2 as po

po.list_programs()
po.code("median filter")
po.show(4)

program = po.get("ml3")
print(program.question)
print(program.algorithm_text)
print(program.flowchart)
source = program.code

po.run(7, image="photo.jpg")
po.save("canny", "canny_edge.py")
po.export("my_lab")
```

## Running a solution directly

Every solution is a plain script. The image programs accept an optional image path and use a built-in
sample image when none is given:

```
python ip05_mean_filter.py
python ip05_mean_filter.py photo.jpg
```

Each program prints its results, saves its figure as `expNN_output.png` and opens the figure window.
