+/** Saves current image to a new file in the current directory. */
+int saveFrame(const IplImage *img) {
+ struct stat stFileInfo;
+ char filename[30] = "snapshot00.png";
+ unsigned int i=0;
+ //find a non-existent filename
+ while(!stat(filename, &stFileInfo)) sprintf(filename, "snapshot%02d.png", ++i);
+ //save image to file
+ return cvSaveImage(filename, img);
+}
+
+/******************************************************************************/
+
+/** Displays in separate window the result of multiplying camera frame (in float)
+ * and recognized mask.
+ * @param floatMat Pointer to the camera frame converted to float matrix.
+ * @param recognizedLayout Index of recognized situation. */
+void displayProduct(const CvMat *floatMat, int recognizedLayout) {
+ CvMat *product = cvCloneMat(floatMat);
+
+ cvMul(floatMat, masks[recognizedLayout], product); // count product
+ displayFloatMat(product, WINDOW_PROD);
+
+ cvReleaseMat(&product);
+}
+
+/******************************************************************************/
+
+/** Normalizes the matrix values and displays them in window specified by name.
+ * @param floatMat Pointer to matrix data to display.
+ * @param windowName Name of window in which to display the image. */
+void displayFloatMat(const CvMat *floatMat, const char *windowName) {
+ double min=0.0, max=0.0;
+ CvMat *normalized = cvCloneMat(floatMat);
+
+ cvMinMaxLoc(floatMat, &min, &max); // find extremes
+ cvConvertScale(floatMat, normalized, 1/(max-min), -(min/(max-min))); // normalize
+ cvShowImage(windowName, normalized);
+
+ cvReleaseMat(&normalized);
+}
+
+/******************************************************************************/
+