Skip to content

Commit

Permalink
reinitialzing library for computer vision essesntials
Browse files Browse the repository at this point in the history
  • Loading branch information
codeperfectplus committed May 3, 2021
1 parent 2d5fe76 commit c01e6ff
Show file tree
Hide file tree
Showing 26 changed files with 150 additions and 9 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added 08. Object Detection/README.md
Empty file.
12 changes: 9 additions & 3 deletions 08. Object Detection/ojectDetectionCVLIB.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
""" Common object detection using CvLib and yolo3 """

import cv2
import matplotlib.pyplot as plt
import cvlib as cv
from cvlib.object_detection import draw_bbox

im = cv2.imread('apple.jpeg')
bbox, label, conf = cv.detect_common_objects(im)
img = cv2.imread('./Media/apple.jpeg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

bbox, label, conf = cv.detect_common_objects(gray)

output_image = draw_bbox(im, bbox, label, conf)

plt.imshow(output_image)
plt.savefig("apple-detected.jpeg")
plt.savefig("./Media/apple-detected.jpeg")
plt.show()
File renamed without changes.
File renamed without changes.
File renamed without changes.
92 changes: 92 additions & 0 deletions 21. Facial Recognition/FaceRec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import os
import face_recognition
import cv2
import numpy as np

video_capture = cv2.VideoCapture(0)


# Create arrays of known face encodings and their names
known_face_encodings = []
known_face_names = []

root_dir = os.path.dirname(os.path.abspath(os.path.abspath(__file__)))
image_dir = os.path.join(root_dir, "images")

for file in os.listdir(image_dir):
if file.endswith == ".jpeg" or ".jpg":
input_face_name = file.split('.')[0]
input_face = face_recognition.load_image_file(os.path.join(image_dir, file))
input_face_encoding = face_recognition.face_encodings(input_face)[0]
known_face_names.append(input_face_name)
known_face_encodings.append(input_face_encoding)

# Initialize some variables
face_locations = []
face_encodings = []
face_names = []
process_this_frame = True

while True:
# Grab a single frame of video
ret, frame = video_capture.read()

# Resize frame of video to 1/4 size for faster face recognition processing
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)

# Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
rgb_small_frame = small_frame[:, :, ::-1]

# Only process every other frame of video to save time
if process_this_frame:
# Find all the faces and face encodings in the current frame of video
face_locations = face_recognition.face_locations(rgb_small_frame)
face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)

face_names = []
for face_encoding in face_encodings:
# See if the face is a match for the known face(s)
matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
name = "Unknown"

# # If a match was found in known_face_encodings, just use the first one.
# if True in matches:
# first_match_index = matches.index(True)
# name = known_face_names[first_match_index]

# Or instead, use the known face with the smallest distance to the new face
face_distances = face_recognition.face_distance(known_face_encodings, face_encoding)
best_match_index = np.argmin(face_distances)
if matches[best_match_index]:
name = known_face_names[best_match_index]

face_names.append(name)
process_this_frame = not process_this_frame


# Display the results
for (top, right, bottom, left), name in zip(face_locations, face_names):
# Scale back up face locations since the frame we detected in was scaled to 1/4 size
top *= 4
right *= 4
bottom *= 4
left *= 4

# Draw a box around the face
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)

# Draw a label with a name below the face
cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)

# Display the resulting image
cv2.imshow('Video', frame)

# Hit 'q' on the keyboard to quit!
if cv2.waitKey(1) & 0xFF == ord('q'):
break

# Release handle to the webcam
video_capture.release()
cv2.destroyAllWindows()
21 changes: 21 additions & 0 deletions 21. Facial Recognition/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Usgaes

1. Add Your Image in `Images` folder. exmaple >> name.jpeg

2. Install the requirements file

```bash
python -m pip install -r requirements.txt
```

3. Run the Script

```bash
python FaceRec.py
```

NOTE:- incase installtation stuck on dlib

```bash
python -m pip install dlib -vvv
```
Binary file added 21. Facial Recognition/images/obama.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 28 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# OpenCv Tutorial
# Computer Vision Essentials

<img align="right" src="Media/opencv-logo-white.png">

- [OpenCv Tutorial](#opencv-tutorial)
- [Computer Vision Essentials](#computer-vision-essentials)
- [Introduction](#introduction)
- [Used Libraries/Packages](#used-librariespackages)
- [How To Run](#how-to-run)
- [Usage](#usage)
- [Support](#support)
Expand All @@ -16,19 +15,42 @@

## Introduction

OpenCV is a cross-platform library using which we can develop real-time computer vision applications. It mainly focuses on image processing, video capture and analysis including features like face detection and object detection. In this tutorial, we explain how you can use OpenCV in your applications.
According to [wikipedia](https://en.wikipedia.org/wiki/Computer_vision, "computer_vision-Wikipedia") -

Computer vision is an interdisciplinary scientific field that deals with how computers can gain high-level understanding from digital images or videos. From the perspective of engineering, it seeks to understand and automate tasks that the human visual system can do.

Computer vision tasks include methods for acquiring, processing, analyzing and understanding digital images, and extraction of high-dimensional data from the real world in order to produce numerical or symbolic information, e.g. in the forms of decisions.

[Read More ...](https://en.wikipedia.org/wiki/Computer_vision, "computer_vision-Wikipedia")

## Used Libraries/Packages

- **OpenCV** - OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library.
- **CVLib** - A simple, high level, easy-to-use open source Computer Vision library for Python.
- **Dlib** - Dlib is a general purpose cross-platform software library written in the programming language C++.
- **PIL/Pillow** - Python Imaging Library is a free and open-source additional library for the Python programming language that adds support for opening, manipulating, and saving many different image file formats
- **Keras** - Keras is the most used deep learning framework among top-5 winning teams on Kaggle.
- **Tensorflow** - TensorFlow is a free and open-source software library for machine learning.
- **Pytessarct** - Python-tesseract is an optical character recognition (OCR) tool for python. That is, it will recognize and “read” the text embedded in images.
- **IPSDK** - IPSDK offers a comprehensive and optimized range of functionalities for 2D and 3D image processing.
- **scikit-image** - scikit-image is an open-source image processing library for the Python programming language. It includes algorithms for segmentation, geometric transformations, color space manipulation, analysis, filtering, morphology, feature detection, and more.
- **Matplotlib** - Matplotlib is a cross-platform, data visualization and graphical plotting library for Python and its numerical extension NumPy.
- **mahotas** - Mahotas is a computer vision and image processing library for Python.

## How To Run

- Install python 3.6+

Create virtual envionment with `pipenv`.

```bash
python -m pip install pipenv
pipenv install -r requirements.txt
pipenv shell
```

NOTE- check the [guide](https://www.tensorflow.org/install) for tenosflow installation for your CPU/GPU. for using tensorflow-gpu install the CUDA-11.0 and necessary libraries.

## Usage

Computer vision allows the computer to perform the same kind of tasks as humans with the same efficiency. There are a two main task which are defined below:
Expand Down Expand Up @@ -75,7 +97,7 @@ For open source projects,Under MIT License.

## Author

- Project : OpenCv Tutorial
- Project : Computer Vision Essentials
- Language : Python
- Github : <https://github.com/codePerfectPlus>
- Website : <http://codeperfectplus.herokuapp.com>
Binary file modified requirements.txt
Binary file not shown.

0 comments on commit c01e6ff

Please sign in to comment.