Hello There
i want to segment image which is capture from cam so here is the code i wrote with help of @berak.
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
using namespace std;
///////////////////////////////////////////image capture and stop camera//////////////////////////////
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat frame; // keep it out of the loop, so we can save latest img.
int64 t0 = getTickCount(); // start time
for(;;)
{
cap >> frame; // get a new frame from camera
int64 t1 = getTickCount(); // time now
double timeRunning = double(t1-t0)/getTickFrequency();
if (timeRunning >= 1.0) // 2 seconds
break;
}
// write last frame to disk:
imwrite("/home/sachin/Desktop/a.jpg", frame);
// the camera will be deinitialized automatically in VideoCapture destructor
////////////////////////////////////Adaptive segmentation /////////////////////////////
Mat src,dst,img;
img = imread("/home/sachin/Desktop/a.jpg"); //read the image data in the file "MyPic.JPG" and store it in 'img'
if (img.empty()) //check whether the image is loaded or not
{
cout << "Error : Image cannot be loaded..!!" << endl;
//system("pause"); //wait for a key press
return -1;
}
cvtColor(img,src,CV_BGR2GRAY);
//cvtColor( src, src_gray, CV_BGR2GRAY );
adaptiveThreshold(src,dst,230,ADAPTIVE_THRESH_MEAN_C,THRESH_BINARY ,5,2);
namedWindow("Adaptive", CV_WINDOW_NORMAL); //create a window with the name "MyWindow"
imshow("Adaptive", dst); //display the image which is stored in the 'img' in the "MyWindow" window
waitKey(0); //wait infinite time for a keypress
destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"
return 0;
}
here camera capture the image and segment the image but camera can't stop.
please help me out.
↧