Skip to content

Commit

Permalink
Merge pull request #1 from spmallick/master
Browse files Browse the repository at this point in the history
Update branches
  • Loading branch information
lipi17dpatnaik authored Apr 6, 2020
2 parents cef8473 + ffe7358 commit 091dc54
Show file tree
Hide file tree
Showing 140 changed files with 11,890 additions and 18 deletions.
23 changes: 17 additions & 6 deletions AgeGender/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
## Code for Age Gender recognition using Deep Learning
# Code for Age Gender recognition using Deep Learning

### Models
## Models
Download models from

Gender Net : https://www.dropbox.com/s/iyv483wz7ztr9gh/gender_net.caffemodel?dl=0"

Age Net : https://www.dropbox.com/s/xfb20y596869vbb/age_net.caffemodel?dl=0"

### Run Code
## Run Code

#### C++
### C++
```
cmake .
make
./AgeGender <input_file>(Leave blank for webcam)
```

#### Python
### Python
```
python AgeGender.py --input <input_file>(Leave blank for webcam)
```

### Sample Result
## Sample Result

![](sample-output.jpg)


# AI Courses by OpenCV

Want to become an expert in AI? [AI Courses by OpenCV](https://opencv.org/courses/) is a great place to start.

<a href="https://opencv.org/courses/">
<p align="center">
<img src="https://www.learnopencv.com/wp-content/uploads/2020/04/AI-Courses-By-OpenCV-Github.png">
</p>
</a>
44 changes: 44 additions & 0 deletions AugmentedRealityWithArucoMarkers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
### Augmented Reality using AruCo Markers in OpenCV

We show how to use the AruCo markers in OpenCV using an augmented reality application to replace the image inside a picture frame on a wall to display new images or videos in the frame.

### Compilation in C++

```
g++ -std=c++11 augmented_reality_with_aruco.cpp -o augmented_reality_with_aruco.out `pkg-config --cflags --libs opencv4`
```

### How to run the code

Command line usage for running the code

* Python

* A single image:

```
python3 augmented_reality_with_aruco.py --image=test.jpg
```

* A video file:

```
python3 augmented_reality_with_aruco.py --video=test.mp4
```

* C++:

* A single image:

```
./augmented_reality_with_aruco.out --image=test.jpg
```

* A video file:

```
./augmented_reality_with_aruco.out --video=test.mp4
```

### Results of YOLOv3
<img src = "./augmented-reality-example.jpg" width = 1000 height = 282/>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
194 changes: 194 additions & 0 deletions AugmentedRealityWithArucoMarkers/augmented_reality_with_aruco.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
// This code is written by Sunita Nayak at BigVision LLC. It is based on the OpenCV project. It is subject to the license terms in the LICENSE file found in this distribution and at http://opencv.org/license.html

// Usage example: ./augmented_reality_with_aruco.out --image=test.jpg
// ./augmented_reality_with_aruco.out --video=test.mp4
#include <fstream>
#include <sstream>
#include <iostream>

#include <opencv2/aruco.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/calib3d.hpp>

const char* keys =
"{help h usage ? | | Usage examples: \n\t\t./augmented_reality_with_aruco.out --image=test.jpg \n\t\t./augmented_reality_with_aruco.out --video=test.mp4}"
"{image i |<none>| input image }"
"{video v |<none>| input video }"
;
using namespace cv;
using namespace aruco;
using namespace std;

int main(int argc, char** argv)
{
CommandLineParser parser(argc, argv, keys);
parser.about("Use this script to do Augmented Reality using Aruco markers in OpenCV.");
if (parser.has("help"))
{
parser.printMessage();
return 0;
}
// Open a video file or an image file or a camera stream.
string str, outputFile;
VideoCapture cap;
VideoWriter video;
Mat frame, blob;

Mat im_src = imread("new_scenery.jpg");

try {

outputFile = "ar_out_cpp.avi";
if (parser.has("image"))
{
// Open the image file
str = parser.get<String>("image");
ifstream ifile(str);
if (!ifile) throw("error");
cap.open(str);
str.replace(str.end()-4, str.end(), "_ar_out_cpp.jpg");
outputFile = str;
}
else if (parser.has("video"))
{
// Open the video file
str = parser.get<String>("video");
ifstream ifile(str);
if (!ifile) throw("error");
cap.open(str);
str.replace(str.end()-4, str.end(), "_ar_out_cpp.avi");
outputFile = str;
}
// Open the webcaom
else cap.open(parser.get<int>("device"));

}
catch(...) {
cout << "Could not open the input image/video stream" << endl;
return 0;
}

// Get the video writer initialized to save the output video
if (!parser.has("image")) {
video.open(outputFile, VideoWriter::fourcc('M','J','P','G'), 28, Size(2*cap.get(CAP_PROP_FRAME_WIDTH), cap.get(CAP_PROP_FRAME_HEIGHT)));
}

// Create a window
static const string kWinName = "Augmented Reality using Aruco markers in OpenCV";
namedWindow(kWinName, WINDOW_NORMAL);

// Process frames.
while (waitKey(1) < 0)
{
// get frame from the video
cap >> frame;

try {
// Stop the program if reached end of video
if (frame.empty()) {
cout << "Done processing !!!" << endl;
cout << "Output file is stored as " << outputFile << endl;
waitKey(3000);
break;
}

vector<int> markerIds;

// Load the dictionary that was used to generate the markers.
Ptr<Dictionary> dictionary = getPredefinedDictionary(DICT_6X6_250);

// Declare the vectors that would contain the detected marker corners and the rejected marker candidates
vector<vector<Point2f>> markerCorners, rejectedCandidates;

// Initialize the detector parameters using default values
Ptr<DetectorParameters> parameters = DetectorParameters::create();

// Detect the markers in the image
detectMarkers(frame, dictionary, markerCorners, markerIds, parameters, rejectedCandidates);

// Using the detected markers, locate the quadrilateral on the target frame where the new scene is going to be displayed.
vector<Point> pts_dst;
float scalingFac = 0.02;//0.015;

Point refPt1, refPt2, refPt3, refPt4;

// finding top left corner point of the target quadrilateral
std::vector<int>::iterator it = std::find(markerIds.begin(), markerIds.end(), 25);
int index = std::distance(markerIds.begin(), it);
refPt1 = markerCorners.at(index).at(1);

// finding top right corner point of the target quadrilateral
it = std::find(markerIds.begin(), markerIds.end(), 33);
index = std::distance(markerIds.begin(), it);
refPt2 = markerCorners.at(index).at(2);

float distance = norm(refPt1-refPt2);
pts_dst.push_back(Point(refPt1.x - round(scalingFac*distance), refPt1.y - round(scalingFac*distance)));

pts_dst.push_back(Point(refPt2.x + round(scalingFac*distance), refPt2.y - round(scalingFac*distance)));

// finding bottom right corner point of the target quadrilateral
it = std::find(markerIds.begin(), markerIds.end(), 30);
index = std::distance(markerIds.begin(), it);
refPt3 = markerCorners.at(index).at(0);
pts_dst.push_back(Point(refPt3.x + round(scalingFac*distance), refPt3.y + round(scalingFac*distance)));

// finding bottom left corner point of the target quadrilateral
it = std::find(markerIds.begin(), markerIds.end(), 23);
index = std::distance(markerIds.begin(), it);
refPt4 = markerCorners.at(index).at(0);
pts_dst.push_back(Point(refPt4.x - round(scalingFac*distance), refPt4.y + round(scalingFac*distance)));

// Get the corner points of the new scene image.
vector<Point> pts_src;
pts_src.push_back(Point(0,0));
pts_src.push_back(Point(im_src.cols, 0));
pts_src.push_back(Point(im_src.cols, im_src.rows));
pts_src.push_back(Point(0, im_src.rows));

// Compute homography from source and destination points
Mat h = cv::findHomography(pts_src, pts_dst);

// Warped image
Mat warpedImage;

// Warp source image to destination based on homography
warpPerspective(im_src, warpedImage, h, frame.size(), INTER_CUBIC);

// Prepare a mask representing region to copy from the warped image into the original frame.
Mat mask = Mat::zeros(frame.rows, frame.cols, CV_8UC1);
fillConvexPoly(mask, pts_dst, Scalar(255, 255, 255), LINE_AA);

// Erode the mask to not copy the boundary effects from the warping
Mat element = getStructuringElement( MORPH_RECT, Size(5,5));
// Mat element = getStructuringElement( MORPH_RECT, Size(3,3));
erode(mask, mask, element);

// Copy the warped image into the original frame in the mask region.
Mat imOut = frame.clone();
warpedImage.copyTo(imOut, mask);

// Showing the original image and the new output image side by side
Mat concatenatedOutput;
hconcat(frame, imOut, concatenatedOutput);

if (parser.has("image")) imwrite(outputFile, concatenatedOutput);
else video.write(concatenatedOutput);

imshow(kWinName, concatenatedOutput);

}
catch(const std::exception& e) {
cout << endl << " e : " << e.what() << endl;
cout << "Could not do homography !! " << endl;
// return 0;
}

}

cap.release();
if (!parser.has("image")) video.release();

return 0;
}
Loading

0 comments on commit 091dc54

Please sign in to comment.