finishing part usable

main
WilliamLiuACPC 3 years ago
parent 8161366eee
commit 6ea7e77447

@ -495,19 +495,62 @@ namespace hdrplus
return sharpImage;
}
void copy_mat_16U_3(u_int16_t* ptr_A, cv::Mat B){
// u_int16_t* ptr_A = (u_int16_t*)A.data;
u_int16_t* ptr_B = (u_int16_t*)B.data;
int H = B.rows;
int W = B.cols;
int end = H*W;
for(int i=0;i<end;i++){
*(ptr_A+i) = *(ptr_B+i);
}
}
// void copy_mat_16U_3(u_int16_t* ptr_A, cv::Mat B){
// // u_int16_t* ptr_A = (u_int16_t*)A.data;
// u_int16_t* ptr_B = (u_int16_t*)B.data;
// for(int r = 0; r < B.rows; r++) {
// for(int c = 0; c < B.cols; c++) {
// *(ptr_A+r*B.cols+c) = *(ptr_B+r*B.cols+c);
// }
// }
// }
cv::Mat processMergedMat(cv::Mat mergedImg, int opencv_type){
cv::Mat m;
u_int16_t* ptr = (u_int16_t*)mergedImg.data;
for(int r = 0; r < mergedImg.rows; r++) {
std::vector<int> dvals;
for(int c = 0; c < mergedImg.cols; c++) {
dvals.push_back(*(ptr+r*mergedImg.cols+c));
}
cv::Mat mline(dvals, true);
cv::transpose(mline, mline);
m.push_back(mline);
}
int ch = CV_MAT_CN(opencv_type);
m = m.reshape(ch);
m.convertTo(m, opencv_type);
return m;
}
void finish::process(std::string burstPath, cv::Mat mergedBayer,int refIdx){
// copy mergedBayer to rawReference
std::cout<<"finish pipeline start ..."<<std::endl;
this->refIdx = refIdx;
this->burstPath = burstPath;
this->mergedBayer = mergedBayer;//loadFromCSV(mergedBayerPath, CV_16UC1);
this->mergedBayer = loadFromCSV("merged_haohua.csv", CV_16UC1);// processMergedMat(mergedBayer,CV_16UC1);//loadFromCSV(mergedBayerPath, CV_16UC1);
load_rawPathList(burstPath);
// read in ref img
bayer_image* ref = new bayer_image(rawPathList[refIdx]);
cv::Mat processedRefImage = postprocess(ref->libraw_processor,params.rawpyArgs);
std::cout<<"size ref: "<<processedRefImage.rows<<"*"<<processedRefImage.cols<<std::endl;
// write reference image
if(params.flags["writeReferenceImage"]){
std::cout<<"writing reference img ..."<<std::endl;
@ -529,7 +572,8 @@ namespace hdrplus
// get the bayer_image of the merged image
bayer_image* mergedImg = new bayer_image(rawPathList[refIdx]);
copy_mat_16U_2(mergedImg->libraw_processor->imgdata.rawdata.raw_image,this->mergedBayer);
// mergedImg->libraw_processor->imgdata.rawdata.raw_image = (uint16_t*)mergedBayer.data;
copy_mat_16U_3(mergedImg->libraw_processor->imgdata.rawdata.raw_image,this->mergedBayer);
cv::Mat processedMerge = postprocess(mergedImg->libraw_processor,params.rawpyArgs);
// write merged image

@ -8,10 +8,18 @@
#include "hdrplus/align.h"
#include "hdrplus/merge.h"
#include "hdrplus/finish.h"
#include <fstream>
namespace hdrplus
{
void writeCSV(std::string filename, cv::Mat m)
{
std::ofstream myfile;
myfile.open(filename.c_str());
myfile<< cv::format(m, cv::Formatter::FMT_CSV) << std::endl;
myfile.close();
}
void hdrplus_pipeline::run_pipeline( \
const std::string& burst_path, \
const std::string& reference_image_path )
@ -26,6 +34,21 @@ void hdrplus_pipeline::run_pipeline( \
// Run merging
merge_module.process( burst_images, alignments );
cv::Mat mergedBayer = burst_images.merged_bayer_image.clone();
std::cout<<std::endl<<"size: "<<mergedBayer.rows<<"*"<<mergedBayer.cols<<std::endl;
// for(int i=0;i<20;i++){
// u_int16_t* ptr = (u_int16_t*)mergedBayer.data;
// for(int j=0;j<20;j++){
// std::cout<<*(ptr+i*mergedBayer.cols+j)<<", ";
// }
// std::cout<<std::endl;
// }
hdrplus::writeCSV("merged.csv",mergedBayer);
// Run finishing
finish_module.process( burst_path, burst_images.merged_bayer_image, burst_images.reference_image_idx);
}

Loading…
Cancel
Save