Currently, I am trying to grab a Mat and do a simple comparison. But now I am stuck at grabbing previous frame. Here is my code.
for(;;){
cap >> frame;
// Clone the current frame:
Mat original = frame.clone();
// Convert the current frame to grayscale:
Mat gray;
cvtColor(original, gray, CV_BGR2GRAY);
vector< Rect_<int> > faces;
Mat face_tmp;
haar_cascade.detectMultiScale(gray, faces,1.2); //scaleFactor = 1.2 for stability
for(int i = 0; i < faces.size(); i++) {
Rect face_i = faces[i];
Mat face = gray(face_i);
Mat face_resized;
cv::resize(face, face_resized, Size(im_width, im_height), 1.0, 1.0, INTER_CUBIC);
Mat Diff = face_resized - face_tmp;
Scalar sumOfface_resized = sum(face_resized);
Scalar sumOfface_tmp = sum(face_tmp);
Scalar sumOfDiff = sum(Diff);
face_tmp = face_resized.clone();
string String_count = static_cast<ostringstream*>( &(ostringstream() << count) )->str();
string String_face_i = static_cast<ostringstream*>( &(ostringstream() << i) )->str();
string filename = String_count + "_" + String_face_i;
cout << "FileName is : " << filename << endl;
cout << "Sum of face_resized is : " << sumOfface_resized << endl;
cout << "Sum of face_tmp is : " << sumOfface_tmp << endl;
cout << "Sum of element differentiation is : " << sumOfDiff << endl;
cout << "xxxxx" << sum(face_tmp) << endl;
}
Here is my output:
FileName is : 0_0
Sum of face_resized is : [5.3287e+06, 0, 0, 0]
Sum of face_tmp is : [0, 0, 0, 0]
Sum of element differentiation is : [5.3287e+06, 0, 0, 0]
xxxxx[5.3287e+06, 0, 0, 0]
FileName is : 1_0
Sum of face_resized is : [5.3287e+06, 0, 0, 0]
Sum of face_tmp is : [0, 0, 0, 0]
Sum of element differentiation is : [5.3287e+06, 0, 0, 0]
xxxxx[5.3287e+06, 0, 0, 0]
FileName is : 2_0
Sum of face_resized is : [5.3287e+06, 0, 0, 0]
Sum of face_tmp is : [0, 0, 0, 0]
Sum of element differentiation is : [5.3287e+06, 0, 0, 0]
xxxxx[5.3287e+06, 0, 0, 0]
FileName is : 3_0
Sum of face_resized is : [5.3287e+06, 0, 0, 0]
Sum of face_tmp is : [0, 0, 0, 0]
Sum of element differentiation is : [5.3287e+06, 0, 0, 0]
xxxxx[5.3287e+06, 0, 0, 0]
Why my previous Mat always zero? I had defined face_tmp outside for loop already. Where am I missing?