SQLite error when creating database in c++
Describe the bug
I installed colmap via vcpkg a while ago (I think 3.8), and was using this code to create a database:
void colmapFunctions::CreateEmptyDatabase(const std::string& database_path) {
// create database
colmap::Database database(database_path);
database.ClearAllTables();
}
I have today updated to colmap 3.10, and the same code runs, but when I open the database in the gui, I see:
colmap.exe gui
SQLite error [C:\dev\vcpkg-ahojnnes\buildtrees\colmap\src\6ae098620c-66eac7d3f9.clean\src\base\database.cc, line 1063]: SQL logic error
To Reproduce Steps to reproduce the behavior:
Use this code to create a database:
void colmapFunctions::CreateEmptyDatabase(const std::string& database_path) {
// create database
colmap::Database database(database_path);
database.ClearAllTables();
}
//optional, use this code to add images / cameras
void colmapFunctions::import_image(const std::string& image_path,
const std::string& database_path, cv::Mat K, cv::Mat D, int image_id )
{
std::cout << "Importing image into the database..." << std::endl;
cv::Mat temp = cv::imread(image_path);
if (temp.rows == 0)
{
return;
}
try {
colmap::Database database(database_path);
colmap::Camera camera;
camera.camera_id = image_id;
camera.model_id = colmap::CameraModelId::kOpenCV;
camera.width = (temp.cols); // width
camera.height = (temp.rows); // height
std::vector<double> parm = { K.at<double>(0, 0), K.at<double>(1, 1), K.at<double>(0, 2), K.at<double>(1, 2), D.at<double>(0, 0),
D.at<double>(0,1), D.at<double>(0,2), D.at<double>(0,3) };
camera.params = parm;
camera.SetFocalLengthX(K.at<double>(0, 0));
camera.SetFocalLengthY(K.at<double>(1, 1));
camera.SetPrincipalPointX(K.at<double>(0, 2));
camera.SetPrincipalPointY(K.at<double>(1, 2));
// Add camera to the database
database.WriteCamera(camera);
std::string base_filename = image_path.substr(image_path.find_last_of("/\\") + 1);
colmap::Image image;
image.SetName(base_filename);
image.SetCameraId(image_id);
image.SetImageId(image_id);
std::cout << image.Name() << std::endl;
database.WriteImage(image);
std::cout << "Image successfully imported into the database." << std::endl;
// Close database connection
database.Close();
}
catch (const std::exception& e) {
std::cerr << "Error importing image: " << e.what() << std::endl;
}
}
in the colmap gui, new project, link the database and image dir. Colmap will crash.
Expected behavior The database to open in colmap without a crash.
Environment:
- OS: Windows 11
- COLMAP Version 3.10
database attached.
additionally, with 3.10 I am seeing a crash in creating twoviewgeometry, using this code:
void ComputeTwoViewGeometry2(const std::string& database_path, int image_id1, int image_id2)
{
colmap::Database database;
database.Open(database_path);
// Load keypoints and matches for both images
const auto keypoints1 = database.ReadKeypoints(image_id1);
const auto keypoints2 = database.ReadKeypoints(image_id2);
const auto matches = database.ReadMatches(image_id1, image_id2);
if (matches.size() == 0) {
std::cout << "No matches found between image " << image_id1 << " and image " << image_id2 << std::endl;
return;
}
// Retrieve camera information
const auto image1 = database.ReadImage(image_id1);
const auto image2 = database.ReadImage(image_id2);
const auto camera1 = database.ReadCamera(image1.CameraId());
const auto camera2 = database.ReadCamera(image2.CameraId());
std::cout << "Camera 1 intrinsics: " << camera1.ParamsToString() << std::endl;
std::cout << "Camera 2 intrinsics: " << camera2.ParamsToString() << std::endl;
std::cout << "Camera 1 model: " << camera1.ModelName() << std::endl;
std::cout << "Camera 2 model: " << camera2.ModelName() << std::endl;
std::cout << "Image 1 : " << image1.Name() << std::endl;
std::cout << "Image 2 : " << image2.Name() << std::endl;
std::cout << "matches size: " << matches.size() << std::endl;
std::cout << "keypoints1 size: " << keypoints1.size() << std::endl;
std::cout << "keypoints2 size: " << keypoints2.size() << std::endl;
colmap::TwoViewGeometryOptions geometry_options_;
colmap::TwoViewGeometry two_view_geometry =
colmap::EstimateCalibratedTwoViewGeometry(camera1,
colmap::FeatureKeypointsToPointsVector(keypoints1),
camera2,
colmap::FeatureKeypointsToPointsVector(keypoints2),
matches,
geometry_options_);
std::cout << "calculated two view stereo" << std::endl;
database.WriteTwoViewGeometry( image1.ImageId(), image2.ImageId(), two_view_geometry);
}
again this was working well in the previous version, and now crashes on EstimateCalibratedTwoViewGeometry with no error message. Thanks!
Same here
Colmap 3.11.1
*** Aborted at 1736866985 (unix time) try "date -d @1736866985" if you are using GNU date *** PC: @ 0x0 (unknown) *** SIGSEGV (@0x8) received by PID 2361020 (TID 0x7f645dffb640) from PID 8; stack trace: *** @ 0x7f6846ccb046 (unknown) @ 0x7f6847642520 (unknown) @ 0x7f6845383abe (unknown) @ 0x7f6845c5dc4e colmap::EstimateCalibratedTwoViewGeometry() @ 0x7f6845c5eb45 colmap::EstimateTwoViewGeometry() @ 0x7f6845af1bcb (unknown) @ 0x7f68461c1a16 colmap::Thread::RunFunc() @ 0x7f681a8dc253 (unknown) @ 0x7f6847694b43 (unknown) @ 0x7f6847726a00 (unknown)
and
terminate called after throwing an instance of 'std::domain_error' what(): Camera model does not exist *** Aborted at 1736941665 (unix time) try "date -d @1736941665" if you are using GNU date *** terminate called recursively terminate called recursively terminate called recursively PC: @ 0x0 (unknown) *** SIGABRT (@0x3e800006c7d) received by PID 27773 (TID 0x7f54acff9640) from PID 27773; stack trace: *** @ 0x7f5882ab2046 (unknown) @ 0x7f5897442520 (unknown) @ 0x7f5897496a7c pthread_kill @ 0x7f5897442476 raise @ 0x7f58974287f3 abort @ 0x7f586a8a2b9e (unknown) @ 0x7f586a8ae20c (unknown) @ 0x7f586a8ae277 std::terminate() @ 0x7f586a8ae4d8 __cxa_throw @ 0x7f589514ceb2 (unknown) @ 0x7f5895c5dc4e colmap::EstimateCalibratedTwoViewGeometry() @ 0x7f5895c5eb45 colmap::EstimateTwoViewGeometry() @ 0x7f5895af1bcb (unknown) @ 0x7f58961c1a16 colmap::Thread::RunFunc() @ 0x7f586a8dc253 (unknown) @ 0x7f5897494b43 (unknown) @ 0x7f5897526a00 (unknown)