Skip to content

Commit

Permalink
Code complete but does not work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhijit J. Theophilus committed May 23, 2017
1 parent 63f66f7 commit 09a44d8
Show file tree
Hide file tree
Showing 11 changed files with 441 additions and 206 deletions.
8 changes: 5 additions & 3 deletions inc/capture.hpp → include/Capture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
#include <map>
#include <vector>

const int DIM = 500;
#include "enVRConsts.hpp"

std::map<std::string, cv::Mat> capture_images();
void save_frames(std::vector<cv::Mat>);
namespace enVR {
std::map<std::string, cv::Mat> capture_images();
void save_frames(std::vector<cv::Mat>);
}

#endif
21 changes: 21 additions & 0 deletions include/Generate.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef _ENVR_POINTGEN
#define _ENVR_POINTGEN

#include <set>
#include <array>
#include <string>
#include <map>
#include <vector>

#include <GL/gl.h>
#include <opencv2/opencv.hpp>

#include "enVRConsts.hpp"

namespace enVR {
point_set extrapolate_projection(cv::Mat frame, std::string face,
double lthresh, double uthresh);
point_set construct_3d_image(point_map pmap);
}

#endif
12 changes: 12 additions & 0 deletions include/Viewer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef _ENVR_VIEWER
#define _ENVR_VIEWER

#include <GL/glut.h>
#include "enVRConsts.hpp"

namespace enVR {
void init_viewer(int* argc, char** argv);
void view_3d_image(point_set pset);
}

#endif
14 changes: 14 additions & 0 deletions include/enVRConsts.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef _ENVR_CONSTANTS
#define _ENVR_CONSTANTS

namespace enVR {
const int dim = 500;

/* typedefs for long types. */
typedef std::array<GLfloat, 3> points;
typedef std::set<points> point_set;
typedef std::map<std::string, point_set> point_map;
typedef std::map<std::string, cv::Mat> frame_map;
}

#endif
33 changes: 26 additions & 7 deletions lib/capture.cpp → lib/Capture.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "capture.hpp"
#include "Capture.hpp"

using namespace enVR;

/*
* capture_images - Captures images sequentially from each of the
Expand All @@ -9,22 +11,22 @@
* None
*
* Returns:
* std::map<std::string, cv::Mat> := Associates the cube face with
* frame_map := Associates the cube face with
* the captured image.
*/

std::map<std::string, cv::Mat> capture_images()
frame_map capture_images()
{
using std::string;
std::map<string, cv::Mat> frames;
std::vector<string> cams {"front", "left", "right", "back"};
std::vector<string> cams {"front", "left", "right", "back", "top"};

// For unit buffering.
std::cout.setf(std::ios::unitbuf);

cv::Mat frame;
for (int i=0; i < cams.size(); i++) {
std::cout << "Capturing image from camera " << i << " ... ";
std::cout << ":: Capturing image from camera " << i << " ... ";
cv::VideoCapture cap(i+1);
cap.set(CV_CAP_PROP_FRAME_WIDTH, DIM);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, DIM);
Expand All @@ -43,14 +45,31 @@ std::map<std::string, cv::Mat> capture_images()
* save_frames - Saves each frame as a jpg file.
*
* Parameters:
* std::map<std::string, cv::Mat> frames := Each entry is the cube
* frame_map frames := Each entry is the cube
* face and it's corresponding frame.
*
* Returns:
* None
*/
void save_frames(std::map<std::string, cv::Mat> frames)
void save_frames(frame_map frames)
{
for (auto it = frames.begin(); it != frames.end(); ++it)
cv::imwrite("img/" + it->first + ".jpg", it->second);
}


/*
* read_frames - Reads each frame from a jpg file.
*
* Returns:
* frame_map frames := Each entry is the cube
* face and it's corresponding frame.
*/
frame_map read_frames()
{
frame_map frames;
std::vector<string> cams {"front", "left", "right", "back", "top"};
for (auto it = cams.begin(); it != cams.end(); ++it) {
cv::Mat frame = cv::imread("img/" + (*it) + ".jpg");
}
}
193 changes: 193 additions & 0 deletions lib/Generate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
#include "Generate.hpp"

using namespace enVR;

// Declarations for this file.

static point_set extrapolate_front(cv::Mat fframe);
static point_set extrapolate_left (cv::Mat lframe);
static point_set extrapolate_back (cv::Mat bframe);
static point_set extrapolate_right(cv::Mat rframe);
static point_set extrapolate_top (cv::Mat tframe);


/*
* extrapolate_projection - Screens all points not within lthresh and
* uthresh. Extrapolates the rest of the frame to create a 3D image.
*
* Parameters:
* cv::Mat frame := The frame to extrapolate.
* std::string face := The face to extrapolate for.
* double lthresh := The lower end threshold.
* double uthresh := The upper end threshold.
*
* Returns:
* point_set := A set of points that form the projection for the
* corresponding face.
*/
point_set extrapolate_projection(cv::Mat frame, std::string face,
double lthresh, double uthresh)
{
point_set pts;
if (face == "front") pts = extrapolate_front(frame, lthresh, uthresh);
else if (face == "left") pts = extrapolate_left (frame, lthresh, uthresh);
else if (face == "back") pts = extrapolate_back (frame, lthresh, uthresh);
else if (face == "right") pts = extrapolate_right(frame, lthresh, uthresh);
else if (face == "top") pts = extrapolate_top (frame, lthresh, uthresh);
return pts;
}


/* Extrapolate the front face. */
static point_set extrapolate_front(cv::Mat fframe, double lthresh,
double uthresh)
{
point_set pts;
for (int i=0; i < DIM; ++i) {
for (int j=0; j < DIM; ++j) {
GLfloat pixel = fframe.at<GLfloat>(i, j);
if (pixel > lthresh && pixel < uthresh) {
for (int k=0; k < DIM; ++k) {
points pt;
pt[0] = j;
pt[1] = DIM - i - 1;
pt[2] = k;
gen_pts.insert(pt);
}
}
}
}
return gen_pts;
}


/* Extrapolate the left face. */
static point_set extrapolate_left(cv::Mat fframe, double lthresh,
double uthresh)
{
point_set pts;
for (int i=0; i < DIM; ++i) {
for (int j=0; j < DIM; ++j) {
GLfloat pixel = fframe.at<GLfloat>(i, j);
if (pixel > lthresh && pixel < uthresh) {
for (int k=0; k < DIM; ++k) {
points pt;
pt[0] = k;
pt[1] = DIM - i - 1;
pt[2] = j;
gen_pts.insert(pt);
}
}
}
}
return gen_pts;
}


/* Extrapolate the back face. */
static point_set extrapolate_back(cv::Mat fframe, double lthresh,
double uthresh)
{
point_set pts;
for (int i=0; i < DIM; ++i) {
for (int j=0; j < DIM; ++j) {
GLfloat pixel = fframe.at<GLfloat>(i, j);
if (pixel > lthresh && pixel < uthresh) {
for (int k=0; k < DIM; ++k) {
points pt;
pt[0] = DIM - j - 1;
pt[1] = DIM - i - 1;
pt[2] = k;
gen_pts.insert(pt);
}
}
}
}
return gen_pts;
}


/* Extrapolate the right face. */
static point_set extrapolate_right(cv::Mat fframe, double lthresh,
double uthresh)
{
point_set pts;
for (int i=0; i < DIM; ++i) {
for (int j=0; j < DIM; ++j) {
GLfloat pixel = fframe.at<GLfloat>(i, j);
if (pixel > lthresh && pixel < uthresh) {
for (int k=0; k < DIM; ++k) {
points pt;
pt[0] = k;
pt[1] = DIM - i - 1;
pt[2] = DIM - j - 1;
gen_pts.insert(pt);
}
}
}
}
return gen_pts;
}


/* Extrapolate the top face. */
static point_set extrapolate_top(cv::Mat fframe, double lthresh,
double uthresh)
{
point_set pts;
for (int i=0; i < DIM; ++i) {
for (int j=0; j < DIM; ++j) {
GLfloat pixel = fframe.at<GLfloat>(i, j);
if (pixel > lthresh && pixel < uthresh) {
for (int k=0; k < DIM; ++k) {
points pt;
pt[0] = j;
pt[1] = k;
pt[2] = i;
gen_pts.insert(pt);
}
}
}
}
return gen_pts;
}


/*
* construct_3d_image - Returns a set of vertices that when drawn
* using OpenGL form a 3D representation of the original projections.
*
* Parameters:
* point_map pmap := A map that associates each face with a set of
* points.
*
* Returns:
* point_set := A set of points to be drawn in OpenGL.
*/
point_set construct_3d_image(point_map pmap)
{
point_set inter;

// Intersection of front and left.
std::set_intersection(pmap["front"].begin(), pmap["front"].end(),
pmap["left"].begin(), pmap["left"].end(),
std::back_inserter(inter));

// Intersection of inter and back.
std::set_intersection(inter.begin(), inter.end(),
pmap["back"].begin(), pmap["back"].end(),
std::back_inserter(inter));

// Intersection of inter and right.
std::set_intersection(inter.begin(),
inter.end(),
pmap["right"].begin(),
pmap["right"].end(),
std::back_inserter(inter));

std::set_intersection(inter.begin(), inter.end(),
pmap["top"].begin(), pmap["top"].end(),
std::back_inserter(inter));

return inter;
}
Loading

0 comments on commit 09a44d8

Please sign in to comment.