Skip to content
Snippets Groups Projects
Commit f186d4d7 authored by Sebastian Gomez-Gonzalez's avatar Sebastian Gomez-Gonzalez
Browse files

Adding Raphael example in an organized manner

parent b54e3aee
No related branches found
No related tags found
No related merge requests found
......@@ -10,3 +10,11 @@ target_link_libraries(color_approach
ball_tracking
${Boost_LIBRARIES}
)
add_executable(log_reg_approach
img_proc/log_reg_approach.cpp
)
target_link_libraries(log_reg_approach
ball_tracking
${Boost_LIBRARIES}
)
#include <ball_tracking/img_proc.hpp>
#include <ball_tracking/utils.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <boost/program_options.hpp>
#include <json.hpp>
using namespace cv;
using namespace std;
using namespace ball_tracking;
using json = nlohmann::json;
int main(int argc, char** argv) {
try {
namespace po = boost::program_options;
po::options_description desc("Options");
desc.add_options()
("help", "Produce help message")
("input,i", po::value<string>(), "path to the input image")
("conf,c", po::value<string>(), "path to the JSON configuration")
("output,o", po::value<string>(), "path to the output image");
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help")) {
cout << desc << endl;
return 0;
}
if (!vm.count("input")) {
cerr << "Error: You should provide the image to process" << endl;
return 1;
}
json jobj = load_json(vm["conf"].as<string>());
Mat model_coef = json2cvmat(jobj.at("model_coefs"));
Mat back = imread(jobj.at("background"), CV_LOAD_IMAGE_COLOR);
if(! back.data ) // Check for invalid input background
{
cout << "Could not open or find the backgroundimage" << std::endl ;
return -1;
}
string fname = vm["input"].as<string>();
Mat img = imread(fname, CV_LOAD_IMAGE_COLOR);
imshow("Color", back);
waitKey(0);
//Calculate the data with coefs
Mat im_proc = quadf_log_reg(img, back, model_coef);
cout << "pix data:" << im_proc.at<double>(340, 290) << endl
<< im_proc.at<double>(342, 291) << endl
<< im_proc.at<double>(290, 340) << endl
<< im_proc.at<double>(2, 2) << endl;
MatIterator_<double> it_ans = im_proc.begin<double>(),end=im_proc.end<double>();
//MatIterator_<Vec3b> it=im_proc.begin<Vec3b>(), end=im_proc.end<Vec3b>();
while(it_ans != end){
//cout << "pix data:" << *it_ans << endl;
double prob = 1.0 / (1.0 + exp(-*it_ans));
//*it_ans = 255*prob;
*it_ans = (prob > 0.95) ? 255 : 0;
it_ans++;
}
imshow("Color", im_proc);
waitKey(0);
//exp(-0.5*im_proc, im_proc);
//im_proc = 255*im_proc;
//imshow("Processed", im_proc);
//waitKey(0);
if (vm.count("output")) {
imwrite(vm["output"].as<string>(), im_proc);
}
return 0;
} catch (std::exception& ex) {
cerr << "Exception: " << ex.what() << endl;
return 1;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment