From 81a5415417cf325adaad627a3e98feb2b5ba23b3 Mon Sep 17 00:00:00 2001
From: Andrey Kamaev <no@email>
Date: Mon, 2 Jul 2012 15:15:40 +0000
Subject: [PATCH] Merged the trunk r8913

---
 apps/traincascade/imagestorage.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/apps/traincascade/imagestorage.cpp b/apps/traincascade/imagestorage.cpp
index 3830a4b38d..0f749f9b01 100644
--- a/apps/traincascade/imagestorage.cpp
+++ b/apps/traincascade/imagestorage.cpp
@@ -154,12 +154,15 @@ bool CvCascadeImageReader::PosReader::get( Mat &_img )
     CV_Assert( _img.rows * _img.cols == vecSize );
     uchar tmp = 0;
     size_t elements_read = fread( &tmp, sizeof( tmp ), 1, file );
-    CV_Assert(elements_read == 1);
+    if( elements_read != 1 )
+        CV_Error( CV_StsBadArg, "Can not get new positive sample. The most possible reason is "
+                                "insufficient count of samples in given vec-file.\n");
     elements_read = fread( vec, sizeof( vec[0] ), vecSize, file );
-    CV_Assert(elements_read == (size_t)(vecSize));
+    if( elements_read != (size_t)(vecSize) )
+        CV_Error( CV_StsBadArg, "Can not get new positive sample. Seems that vec-file has incorrect structure.\n");
 
     if( feof( file ) || last++ >= count )
-        return false;
+        CV_Error( CV_StsBadArg, "Can not get new positive sample. vec-file is over.\n");
 
     for( int r = 0; r < _img.rows; r++ )
     {