// Standard include files
#include <opencv2/opencv.hpp>
#include <opencv2/tracking.hpp>
using namespace cv;
using namespace std;
int main(int argc, char **argv)
{
// Set up tracker.
// Instead of MIL, you can also use
// BOOSTING, KCF, TLD, MEDIANFLOW or GOTURN
Ptr<Tracker> tracker = Tracker::create( "MIL" );
// Read video
VideoCapture video("videos/chaplin.mp4");
// Check video is open
if(!video.isOpened())
{
cout << "Could not read video file" << endl;
return 1;
}
// Read first frame.
Mat frame;
video.read(frame);
// Define an initial bounding box
Rect2d bbox(287, 23, 86, 320);
// Uncomment the line below if you
// want to choose the bounding box
// bbox = selectROI(frame, false);
// Initialize tracker with first frame and bounding box
tracker->init(frame, bbox);
while(video.read(frame))
{
// Update tracking results
tracker->update(frame, bbox);
// Draw bounding box
rectangle(frame, bbox, Scalar( 255, 0, 0 ), 2, 1 );
// Display result
imshow("Tracking", frame);
int k = waitKey(1);
if(k == 27) break;
}
return 0;
}
Mat img = imread(filename,IMREAD_GRAYSCALE);
for( size_t nrow = 0; nrow < img.rows; nrow++)
{
for(size_t ncol = 0; ncol < img.cols; ncol++)
{
uchar val = img.at<uchar>(nrow,ncol);
}
}
Mat img = imread(filename,IMREAD_COLOR);
for( size_t nrow = 0; nrow < img.rows; nrow++)
{
for(size_t ncol = 0; ncol < img.cols; ncol++)
{
Vec3i bgr = img.at<Vec3b>(nrow,ncol);//用Vec3b也行
cout << "("<<bgr.val[0]<<","
<<bgr.val[1]<<","
<<bgr.val[2]<<")";
}
cout << endl;
}
Mat img = imread(filename);
typedef BOOST_TYPEOF(*img.data) ElementType
for( size_t nrow = 0; nrow < img.rows; nrow++)
{
for(size_t ncol = 0; ncol < img.cols; ncol++)
{
cout<<img.at<ElementType>(nrow,ncol);
}
}
Mat img = imread(filename,IMREAD_COLOR);
for( size_t nrow = 0; nrow < img3.rows; nrow++)
{
uchar* data = img.ptr<uchar>(nrow);
for(size_t ncol = 0; ncol < img.cols * img.channels(); ncol++)
{
cout << int( data[ncol] ) ;
}
cout << endl;
}
Mat img = imread(filename,IMREAD_GRAYSCALE);
MatIterator_<uchar> it = img.begin<uchar>(), it_end = img.end<uchar>();
for(int cnt = 1; it != it_end; ++it)
{
cout << ( int(*it) ) ;
if( (cnt++ % img.cols) ==0 )
{
cout << endl;
}
}
Mat img(rows, cols,CV_8U, Scalar(0));
for( size_t nrow = 0; nrow < img.rows; nrow++)
{
for(size_t ncol = 0; ncol < img.cols; ncol++)
{
cout<<(int)(*(img.data+img.step[0]*nrow+img.step[1]*ncol));
}
}