To include the following directories:
C:\OpenCV-2.4.5\opencv\build\include
C:\OpenCV-2.4.5\opencv\build\include\opencv
To include the library's path where you've compiled for OpenCV-2.4.5
C:\OpenCV-2.4.5\opencv\vs2010\lib\Release
Also remember to add the files below along with your project
opencv_highgui245.lib
opencv_imgproc245.lib
opencv_core245.lib
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <msclr/marshal_cppstd.h>
using namespace cv;
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Mat src;
CvRect Rect;
if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK){
src = imread( msclr::interop::marshal_as< std::string >(openFileDialog1->FileName), CV_LOAD_IMAGE_COLOR);
if (src.empty())
return;
Mat hsv;
cvtColor(src, hsv, CV_BGR2HSV);
Mat bw;
inRange(hsv, Scalar(19, 134, 113), Scalar(34, 255, 255), bw);
imshow("src", src);
imshow("hsv", hsv);
imwrite( "hsv.jpg", hsv );
imshow("bw", bw);
imwrite( "mask.jpg", bw );
vector<vector<cv::Point> > contours;
findContours(bw.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
Mat dst = Mat::zeros(src.size(), src.type());
drawContours(dst, contours, -1, Scalar::all(255), CV_FILLED);
imshow("bw2", dst);
imwrite( "mask2.jpg", dst );
dst &= src;
imshow("dst", dst);
imwrite( "segmentation result.jpg", dst );
waitKey(0);
}