#include <iostream>
#include <fstream>
#include <string>
#include "opencv2/opencv_modules.hpp"
#include <opencv2/core/utility.hpp>
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/stitching/detail/autocalib.hpp"
#include "opencv2/stitching/detail/blenders.hpp"
#include "opencv2/stitching/detail/timelapsers.hpp"
#include "opencv2/stitching/detail/camera.hpp"
#include "opencv2/stitching/detail/exposure_compensate.hpp"
#include "opencv2/stitching/detail/matchers.hpp"
#include "opencv2/stitching/detail/motion_estimators.hpp"
#include "opencv2/stitching/detail/seam_finders.hpp"
#include "opencv2/stitching/detail/warpers.hpp"
#include "opencv2/stitching/warpers.hpp"
#ifdef HAVE_OPENCV_XFEATURES2D
#include "opencv2/xfeatures2d/nonfree.hpp"
#endif
#define ENABLE_LOG 1
#define LOG(msg) std::cout << msg
#define LOGLN(msg) std::cout << msg << std::endl
using namespace std;
using namespace cv;
using namespace cv::detail;
// Default command line args
#if 1
#define DLL_API __declspec(dllexport)
#else
#define DLL_API __declspec(dllimport)
#endif
extern "C" { //由于编译过程的原因,python一般只支持c的接口
typedef struct ImageBase {
int w; //图像的宽
int h; //图像的高
int c; //通道数
unsigned char *data; //我们要写python和c++交互的数据结构,0-255的单字符指针
}ImageMeta;
//typedef ImageBase ImageMeta;
DLL_API int Stitch(ImageMeta *im1, ImageMeta *im2);//函数导出,要改
};
//vector<String> img_names;
int num_images;
bool preview = false;
bool try_cuda = false;
double work_megapix = 0.6;
double seam_megapix = 0.1;
double compose_megapix = -1;
float conf_thresh = 1.f;
#ifdef HAVE_OPENCV_XFEATURES2D
string features_type = "surf";
#else
string features_type = "orb";
#endif
string matcher_type = "homography";
string estimator_type = "homography";
string ba_cost_func = "ray";
string ba_refine_mask = "xxxxx";
bool do_wave_correct = true;
WaveCorrectKind wave_correct = detail::WAVE_CORRECT_HORIZ;
bool save_graph = false;
std::string save_graph_to;
string warp_type = "spherical";
int expos_comp_type = ExposureCompensator::GAIN_BLOCKS;
int expos_comp_nr_feeds = 1;
int expos_comp_nr_filtering = 2;
int expos_comp_block_size = 32;
float match_conf = 0.3f;
string seam_find_type = "gc_color";
int blend_type = Blender::MULTI_BAND;
int timelapse_type = Timelapser::AS_IS;//延时摄影
float blend_strength = 5;
string result_name = "D:/result.jpg";//
bool timelapse = false;//首先定义timelapse的默认布尔类型为False
int range_width = -1;
DLL_API int Stitch(ImageMeta *im1, ImageMeta *im2)//入参两个数组指针,出参一个数组指针
//vector<Mat> img_list
{//一个int数;一个图片类型的列表
//predict先判断长度 然后长度作为一个参数传给
//preview = true;
//try_cuda = true;
//preview = true;
//result = 'D:/result.jpg';
//work_megapix = -1;
//features_type = "orb";
Mat img1 = Mat::zeros(Size(im1->w, im1->h), CV_8UC3);
//先从输入的指针对象提取w,h,data;将python传来的参数转变成C处理的格式。用的是相同的结构:结构体。
img1.data = im1->data;
Mat img2 = Mat::zeros(Size(im2->w, im2->h), CV_8UC3);
//先从输入的指针对象提取w,h,data;将python传来的参数转变成C处理的格式。用的是相同的结构:结构体。
img2.data = im2->data;
//Mat img1, img2;
//img1 = imread("D:/1Hill.jpg");
//img2 = imread("D:/2Hill.jpg");
vector<Mat> ALLimages(2);
ALLimages[0] = img1.clone();
ALLimages[1] = img2.clone();
//img_names.push_back("D:/1Hill.jpg");
//img_names.push_back("D:/2Hill.jpg");//??
//img_names.push_back("D:/3Hill.jpg");//??
num_images = 2;
#if ENABLE_LOG
int64 app_start_time = getTickCount();
#endif
#if 0
cv::setBreakOnError(true);
#endif
//int retval = parseCmdArgs(argc, argv);
//if (retval)
//return retval;
// Check if have enough images
//int num_images = static_cast<int>(img_names.size());
if (num_images < 2)
{
LOGLN("Need more images");
return -1;
}
double work_scale = 1, seam_scale = 1, compose_scale = 1;
bool is_work_scale_set = false, is_seam_scale_set = false, is_compose_scale_set = false;
LOGLN("Finding features...");
#if ENABLE_LOG
int64 t = getTickCount();
#endif
Ptr<Feature2D> finder;
if (features_type == "orb")
{
finder = ORB::create();
}
else if (features_type == "akaze")
{
finder = AKAZE::create();
}
#ifdef HAVE_OPENCV_XFEATURES2D
else if (features_type == "surf")
{
finder = xfeatures2d::SURF::create();
}
else if (features_type == "sift") {
finder = xfeatures2d::SIFT::create();
}
#endif
else
{
cout << "Unknown 2D features type: '" << features_type << "'.\n";
r
Python调用C++动态库,实现图像拼接(调用输出结果有问题)
最新推荐文章于 2024-05-16 10:29:25 发布