Created
April 13, 2015 10:26
-
-
Save bangonkali/ef63a03abc471972f997 to your computer and use it in GitHub Desktop.
MongoDB C++ Library, OpenCV Integration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SDKDDKVer.h> | |
#include <winsock2.h> | |
#include <Windows.h> | |
#pragma warning(disable:4819) | |
#pragma warning(disable:4996) | |
// for OpenCV2 | |
#include "opencv2/imgproc/imgproc.hpp" | |
#include "opencv2/objdetect/objdetect.hpp" | |
#include "opencv2/gpu/gpu.hpp" | |
#include "opencv2/highgui/highgui.hpp" | |
#ifdef _DEBUG | |
#pragma comment(lib, "opencv_core2410d.lib") | |
#pragma comment(lib, "opencv_imgproc2410d.lib") | |
#pragma comment(lib, "opencv_objdetect2410d.lib") | |
#pragma comment(lib, "opencv_gpu2410d.lib") | |
#pragma comment(lib, "opencv_highgui2410d.lib") | |
#else | |
#pragma comment(lib, "opencv_core2410.lib") | |
#pragma comment(lib, "opencv_imgproc2410.lib") | |
#pragma comment(lib, "opencv_objdetect2410.lib") | |
#pragma comment(lib, "opencv_gpu2410.lib") | |
#pragma comment(lib, "opencv_highgui2410.lib") | |
#endif | |
#include <cstdlib> | |
#include <iostream> | |
#include "mongo/client/dbclient.h" | |
int main(int argc, char* argv[]) | |
{ | |
//BSONObjBuilder b; | |
//b.append("name", "Joe"); | |
//b.append("age", 33); | |
//BSONObj p = b.obj(); | |
mongo::client::initialize(); | |
try { | |
mongo::DBClientConnection c; | |
c.connect("phtemhm-autovm1"); | |
std::cout << "connected ok" << std::endl; | |
} catch( const mongo::DBException &e ) { | |
std::cout << "caught " << e.what() << std::endl; | |
} | |
cv::Mat src_img, template_img; | |
cv::Mat result_mat; | |
cv::Mat debug_img; | |
template_img = cv::imread("..\\img\\lena_eye.jpg", CV_LOAD_IMAGE_GRAYSCALE); | |
if (template_img.data == NULL) { | |
printf("cv::imread() failed...\n"); | |
return -1; | |
} | |
src_img = cv::imread("..\\img\\lena.jpg", CV_LOAD_IMAGE_GRAYSCALE); | |
if (src_img.data == NULL) { | |
printf("cv::imread() failed...\n"); | |
return -1; | |
} | |
cv::cvtColor(src_img, debug_img, CV_GRAY2BGR); | |
while(true) { | |
// method: CV_TM_SQDIFF, CV_TM_SQDIFF_NORMED, CV_TM _CCORR, CV_TM_CCORR_NORMED, CV_TM_CCOEFF, CV_TM_CCOEFF_NORMED | |
int match_method = CV_TM_CCORR_NORMED; | |
cv::matchTemplate(src_img, template_img, result_mat, match_method); | |
cv::normalize(result_mat, result_mat, 0, 1, cv::NORM_MINMAX, -1, cv::Mat()); | |
double minVal; double maxVal; | |
cv::Point minLoc, maxLoc, matchLoc; | |
cv::minMaxLoc(result_mat, &minVal, &maxVal, &minLoc, &maxLoc, cv::Mat() ); | |
if( match_method == CV_TM_SQDIFF || match_method == CV_TM_SQDIFF_NORMED ) matchLoc = minLoc; | |
else matchLoc = maxLoc; | |
cv::rectangle( | |
debug_img, | |
matchLoc, | |
cv::Point(matchLoc.x + template_img.cols , matchLoc.y + template_img.rows), | |
CV_RGB(255,0,0), | |
3); | |
cv::imshow("debug_img", debug_img); | |
int c = cv::waitKey(1); | |
if (c == 27) break; | |
} | |
std::cout << "Press Enter Key to continue."; | |
//char x = getchar(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment