MasteringOpenCV / code

Code for the book "Mastering OpenCV with Practical Computer Vision Projects" by Packt Publishing 2012.
Other
2.73k stars 1.65k forks source link

Chapter 4 :Structure From Motion build error #29

Closed Reena24 closed 10 years ago

Reena24 commented 10 years ago

Hello i have made the required changes in the code and now I am able to configure the code. I have few build error which i have no clue on how to solve as am a beginner

This post has NOT been accepted by the mailing list yet. This post was updated on Mar 04, 2014; 1:04pm. Hi I am trying to execute the code from https://github.com/MasteringOpenCV/code/tree/master/Chapter4_StructureFromMotion I have built it using cmake but i get these error

1>------ Build started: Project: ZERO_CHECK, Configuration: Debug Win32 ------ 1>Build started 3/4/2014 1:37:00 PM. 1>InitializeBuildStatus: 1> Creating "Win32\Debug\ZERO_CHECK\ZERO_CHECK.unsuccessfulbuild" because "AlwaysCreate" was specified. 1>FinalizeBuildStatus: 1> Deleting file "Win32\Debug\ZERO_CHECK\ZERO_CHECK.unsuccessfulbuild". 1> Touching "Win32\Debug\ZERO_CHECK\ZERO_CHECK.lastbuildstate". 1> 1>Build succeeded. 1> 1>Time Elapsed 00:00:00.07 2>------ Build started: Project: ExploringSfMExec, Configuration: Debug Win32 ------ 2>Build started 3/4/2014 1:37:00 PM. 2>InitializeBuildStatus: 2> Touching "ExploringSfMExec.dir\Debug\ExploringSfMExec.unsuccessfulbuild". 2>CustomBuild: 2> All outputs are up-to-date. 2>ClCompile: 2> All outputs are up-to-date. 2>ManifestResourceCompile: 2> All outputs are up-to-date. 2>LINK : fatal error LNK1104: cannot open file 'C:\Qt\4.8.0\lib\QtGuid4.lib' 2> 2>Build FAILED. 2> 2>Time Elapsed 00:00:00.18 3>------ Build started: Project: ALL_BUILD, Configuration: Debug Win32 ------ 3>Build started 3/4/2014 1:37:00 PM. 3>InitializeBuildStatus: 3> Creating "Win32\Debug\ALL_BUILD\ALL_BUILD.unsuccessfulbuild" because "AlwaysCreate" was specified. 3>CustomBuild: 3> Build all projects 3>FinalizeBuildStatus: 3> Deleting file "Win32\Debug\ALL_BUILD\ALL_BUILD.unsuccessfulbuild". 3> Touching "Win32\Debug\ALL_BUILD\ALL_BUILD.lastbuildstate". 3> 3>Build succeeded. 3> 3>Time Elapsed 00:00:00.07 ========== Build: 2 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// The code is /*****

#define WIN32_LEAN_AND_MEAN 1 
#define NOMINMAX 1 
#include <windows.h>

endif

include <gl/GL.h>//#include <GL/gl.h>

include <gl/GLU.h>// #include <GL/glu.h>

ifndef WIN32

include

endif

using namespace std; using namespace cv;

std::vectorcv::DMatch FlipMatches(const std::vectorcv::DMatch& matches) { std::vectorcv::DMatch flip; for(int i=0;i<matches.size();i++) { flip.push_back(matches[i]); swap(flip.back().queryIdx,flip.back().trainIdx); } return flip; }

std::vectorcv::Point3d CloudPointsToPoints(const std::vector cpts) { std::vectorcv::Point3d out; for (unsigned int i=0; i<cpts.size(); i++) { out.push_back(cpts[i].pt); } return out; }

void GetAlignedPointsFromMatch(const std::vectorcv::KeyPoint& imgpts1, const std::vectorcv::KeyPoint& imgpts2, const std::vectorcv::DMatch& matches, std::vectorcv::KeyPoint& pt_set1, std::vectorcv::KeyPoint& pt_set2) { for (unsigned int i=0; i<matches.size(); i++) { // cout << "matches[i].queryIdx " << matches[i].queryIdx << " matches[i].trainIdx " << matches[i].trainIdx << endl; assert(matches[i].queryIdx < imgpts1.size()); pt_set1.push_back(imgpts1[matches[i].queryIdx]); assert(matches[i].trainIdx < imgpts2.size()); pt_set2.push_back(imgpts2[matches[i].trainIdx]); }
}

void KeyPointsToPoints(const vector& kps, vector& ps) { ps.clear(); for (unsigned int i=0; i<kps.size(); i++) ps.push_back(kps[i].pt); }

void PointsToKeyPoints(const vector& ps, vector& kps) { kps.clear(); for (unsigned int i=0; i<ps.size(); i++) kps.push_back(KeyPoint(ps[i],1.0f)); }

define intrpmnmx(val,min,max) (max==min ? 0.0 : ((val)-min)/(max-min))

void drawArrows(Mat& frame, const vector& 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 imshow250x250(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::vectorcv::Mat& images, std::vectorstd::string& images_names, double downscale_factor) { if (dir_name == NULL) { return; }

    string dir_name_ = string(dir_name); 
    vector<string> 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<files_.size(); i++) { 
            if (files_[i][0] == '.' || !(hasEndingLower(files_[i],"jpg")||hasEndingLower(files_[i],"png"))) { 
                    continue; 
            } 
            cv::Mat m_ = cv::imread(string(dir_name_).append("/").append(files_[i])); 
            if(downscale_factor != 1.0) 
                    cv::resize(m_,m_,Size(),downscale_factor,downscale_factor); 
            images_names.push_back(files_[i]); 
            images.push_back(m_); 
    } 

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Is some header file missing ????? Actually i dont have a file like C:\Qt\4.8.0\lib\QtGuid4.lib but i do have qt installed it is opensource it is installed in E:\OpenCV\dep\qt\qt-everywhere-opensource-src-4.8.4 and i have also installed PCL 1.6.0 All-In-One Installer but i checked it does not have Qt 4.8.0 in the 3rd party library. What should i do

royshil commented 10 years ago

I suggest you try to use the newer version of the SfM library: https://github.com/royshil/SfM-Toy-Library It doesn't use PCL anymore and has a more streamlined build so it may be easier to use, but it has the same core SfM code.

Reena24 commented 10 years ago

Hi i did what u suggested of trying the new version of Sfm library : https://github.com/royshil/SfM-Toy-Library but i get compilation error when i try to build it 2>------ Build started: Project: SfMToyLibrary, Configuration: Release Win32 ------ 2>Build started 3/8/2014 7:50:20 PM. 2>InitializeBuildStatus: 2> Touching "SfMToyLibrary.dir\Release\SfMToyLibrary.unsuccessfulbuild". 2>CustomBuild: 2> All outputs are up-to-date. 2>cl : Command line error D8021: invalid numeric argument '/Wno-sign-compare' 2> 2>Build FAILED. 2> 2>Time Elapsed 00:00:00.11 3>------ Build started: Project: SfMToyUI, Configuration: Release Win32 ------ 3>Build started 3/8/2014 7:50:20 PM. 3>InitializeBuildStatus: 3> Touching "SfMToyUI.dir\Release\SfMToyUI.unsuccessfulbuild". 3>CustomBuild: 3> All outputs are up-to-date. 3>ClCompile: 3> ViewerInterface.cpp 3> sfmviewer.cpp 3> moc_ViewerInterface.cxx 3> moc_sfmviewer.cxx 3> main.cpp 3>C:\Users\Reeba\Desktop\SfM-Toy-Library-master\SfMToyLib\Distance.h(70): warning C4172: returning address of local variable or temporary 3> Generating Code... 3>LINK : fatal error LNK1181: cannot open input file 'SfMToyLib\Release\SfMToyLibrary.lib' 3> 3>Build FAILED. 3> 3>Time Elapsed 00:00:18.09 4>------ Skipped Build: Project: ALL_BUILD, Configuration: Release Win32 ------ 4>Project not selected to build for this solution configuration ========== Build: 1 succeeded, 2 failed, 0 up-to-date, 1 skipped ==========

royshil commented 10 years ago

Looks like the .lib file was not built, try to clean and re-build the project

Reena24 commented 10 years ago

I tried clean and rebuilt a lot of times but i still get the same error

Reena24 commented 10 years ago

It finally worked thankyou for your help

thbupt commented 8 years ago

@Reena24 I just have the same error:LINK : fatal error LNK1181: cannot open input file 'SfMToyLib\Release\SfMToyLibrary.lib' How did you solve it?