GeezerVison is showing raw.githubusercontent.com — raw.githubusercontent.com /*****************************************************************************
* ExploringSfMWithOpenCV
******************************************************************************
* by Roy Shilkrot, 5th Dec 2012
* http://www.morethantechnical.com/
******************************************************************************
* Ch4 of the book "Mastering OpenCV with Practical Computer Vision Projects"
* Copyright Packt Publishing 2012.
* http://www.packtpub.com/cool-projects-with-opencv/book
*****************************************************************************/
#include "Common.h"
#include
#include
#include
#ifndef WIN32
#include
#endif
using namespace std;
using namespace cv;
std::vector FlipMatches(const std::vector& matches) {
std::vector flip;
for(int i=0;i CloudPointsToPoints(const std::vector cpts) {
std::vector out;
for (unsigned int i=0; i& imgpts1,
const std::vector& imgpts2,
const std::vector& matches,
std::vector& pt_set1,
std::vector& pt_set2)
{
for (unsigned int i=0; i& kps, vector& ps) {
ps.clear();
for (unsigned int i=0; i& ps, vector& kps) {
kps.clear();
for (unsigned int i=0; i& prevPts, const vector& nextPts, const vector& status, const vector& verror, const Scalar& _line_color)
{
double minVal,maxVal; minMaxIdx(verror,&minVal,&maxVal,0,0,status);
int line_thickness = 1;
for (size_t i = 0; i < prevPts.size(); ++i)
{
if (status[i])
{
double alpha = intrpmnmx(verror[i],minVal,maxVal); alpha = 1.0 - alpha;
Scalar line_color(alpha*_line_color[0],
alpha*_line_color[1],
alpha*_line_color[2]);
Point p = prevPts[i];
Point q = nextPts[i];
double angle = atan2((double) p.y - q.y, (double) p.x - q.x);
double hypotenuse = sqrt( (double)(p.y - q.y)*(p.y - q.y) + (double)(p.x - q.x)*(p.x - q.x) );
if (hypotenuse < 1.0)
continue;
// Here we lengthen the arrow by a factor of three.
q.x = (int) (p.x - 3 * hypotenuse * cos(angle));
q.y = (int) (p.y - 3 * hypotenuse * sin(angle));
// Now we draw the main line of the arrow.
line(frame, p, q, line_color, line_thickness);
// Now draw the tips of the arrow. I do some scaling so that the
// tips look proportional to the main line of the arrow.
p.x = (int) (q.x + 9 * cos(angle + CV_PI / 4));
p.y = (int) (q.y + 9 * sin(angle + CV_PI / 4));
line(frame, p, q, line_color, line_thickness);
p.x = (int) (q.x + 9 * cos(angle - CV_PI / 4));
p.y = (int) (q.y + 9 * sin(angle - CV_PI / 4));
line(frame, p, q, line_color, line_thickness);
}
}
}
bool hasEnding (std::string const &fullString, std::string const &ending)
{
if (fullString.length() >= ending.length()) {
return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));
} else {
return false;
}
}
bool hasEndingLower (string const &fullString_, string const &_ending)
{
string fullstring = fullString_, ending = _ending;
transform(fullString_.begin(),fullString_.end(),fullstring.begin(),::tolower); // to lower
return hasEnding(fullstring,ending);
}
void imshow_250x250(const string& name_, const Mat& patch) {
Mat bigpatch; cv::resize(patch,bigpatch,Size(250,250));
imshow(name_,bigpatch);
}
void open_imgs_dir(char* dir_name, std::vector& images, std::vector& images_names, double downscale_factor) {
if (dir_name == NULL) {
return;
}
string dir_name_ = string(dir_name);
vector files_;
#ifndef WIN32
//open a directory the POSIX way
DIR *dp;
struct dirent *ep;
dp = opendir (dir_name);
if (dp != NULL)
{
while (ep = readdir (dp)) {
if (ep->d_name[0] != '.')
files_.push_back(ep->d_name);
}
(void) closedir (dp);
}
else {
cerr << ("Couldn't open the directory");
return;
}
#else
//open a directory the WIN32 way
HANDLE hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATA fdata;
if(dir_name_[dir_name_.size()-1] == '\\' || dir_name_[dir_name_.size()-1] == '/') {
dir_name_ = dir_name_.substr(0,dir_name_.size()-1);
}
hFind = FindFirstFile(string(dir_name_).append("\\*").c_str(), &fdata);
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if (strcmp(fdata.cFileName, ".") != 0 &&
strcmp(fdata.cFileName, "..") != 0)
{
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
continue; // a diretory
}
else
{
files_.push_back(fdata.cFileName);
}
}
}
while (FindNextFile(hFind, &fdata) != 0);
} else {
cerr << "can't open directory\n";
return;
}
if (GetLastError() != ERROR_NO_MORE_FILES)
{
FindClose(hFind);
cerr << "some other error with opening directory: " << GetLastError() << endl;
return;
}
FindClose(hFind);
hFind = INVALID_HANDLE_VALUE;
#endif
for (unsigned int i=0; i |