title: Visual Studio bug with OpenCV?
body: <p>I have a project made with Visual Studio 2012 using OpenCV, it captures video from an webcam and check if there are faces in. I tested a few days and it was working but today i tested it again and is giving me this error and i dont know what to do! I havent changed anything with the code or the Paths of OpenCV.....</p>
  
  <p>Code:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;math.h&gt;
  #include&lt;opencv\cv.h&gt;
  #include&lt;opencv\highgui.h&gt;
  #include&lt;opencv2\objdetect\objdetect.hpp&gt;
  #include&lt;opencv2\highgui\highgui.hpp&gt;
  #include&lt;opencv2\imgproc\imgproc.hpp&gt;
  #include&lt;vector&gt;
  
  using namespace cv;
  using namespace std;
  
  int main()
      {
      CascadeClassifier face_cascade;
      if(!face_cascade.load("c:\\haar\\haarcascade_frontalface_alt2.xml")) {
          printf("Erro a carregar o ficheiro cascade para o rosto!");
          return 1;
      }
      VideoCapture capture(0);
      if(!capture.isOpened())
      {
          printf("Erro ao tentar iniciar a camara!");
          return 1;
      }
      Mat cap_img,gray_img;
      vector&lt;Rect&gt; faces;
      while(1)
      {
          capture &gt;&gt; cap_img;
          cvtColor(cap_img, gray_img, CV_RGB2GRAY);
          cv::equalizeHist(gray_img,gray_img);
          face_cascade.detectMultiScale(gray_img, faces, 1.1, 10, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0), cvSize(300,300));
          for(int i=0; i &lt; faces.size();i++)
          {
              Point pt1(faces[i].x+faces[i].width, faces[i].y+faces[i].height);
              Point pt2(faces[i].x,faces[i].y);
              rectangle(cap_img, pt1, pt2, cvScalar(191,191,191), 2, 8, 0);
          }
          imshow("Result", cap_img);
          if (waitKey(1)==27);
              break;
      }
      return 0;
  }
  </code></pre>
  
  <p>Picture:</p>
  
  <p><img src="https://i.imgur.com/MkcpX1Y.png" alt="Image of the error"></p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The errors pop-out at the same time but i must close the window to check the others so:</p>
  
  <p>1st Error (Window one): 
  Unhandled exception at at 0x74FB1D4D in Detetor de Rosto.exe Microsoft C++ exception:cv::Exception at memory location 0x00D6C280.</p>
  
  <hr>
  
  <p>2nd Error (Console one): OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv::cvtColor, file C:\buildslave64\win64_amdoc1\2_4_PackSlave-win32-vc11-shared\opencv\modules\imgproc\src\color.cpp, line 3737</p>
  
  <hr>
  
  <p>3rd Error (Down one): 
  KernelBase.dll!_RaiseException@16()
  msvcr110.dll!_CxxThrowException(void<em>pExceptionObject,const_s_ThrowInfo</em>pThrowInfo) Line 152
  opencv_core249.dll!59807dc5()
  [Frames below may be incorrect and/or missing, no symbols loaded for opencv_core249.dll]</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>Also when i close the errors message it opens an file called <em>Throw.cpp</em> and it contains this code:</p>
  
  <pre><code>/***
  *throw.cxx - Implementation of the 'throw' command.
  *
  *       Copyright (c) Microsoft Corporation. All rights reserved.
  *
  *Purpose:
  *       Implementation of the exception handling 'throw' command.
  *
  *       Entry points:
  *       * _CxxThrowException - does the throw.
  ****/
  
  #include &lt;stddef.h&gt;
  #include &lt;windows.h&gt;
  #include &lt;mtdll.h&gt;
  #include &lt;ehdata.h&gt;
  #include &lt;eh.h&gt;
  #include &lt;ehhooks.h&gt;
  #include &lt;ehassert.h&gt;
  #include &lt;trnsctrl.h&gt;
  
  
  #pragma hdrstop
  
  //
  // Make sure PULONG_PTR is available
  //
  
  #if defined(_X86_)
  #define _W64 __w64
  #else
  #define _W64
  #endif
  
  #if !defined(PULONG_PTR)
  #if defined(_WIN64)
  typedef unsigned __int64 *      PULONG_PTR;
  #else
  typedef _W64 unsigned long *    PULONG_PTR;
  #endif
  #endif
  
  #if defined(_M_X64)
  extern "C" PVOID _ReturnAddress(VOID);
  #pragma intrinsic(_ReturnAddress)
  #endif
  
  /////////////////////////////////////////////////////////////////////////////
  //
  // _CxxThrowException - implementation of 'throw'
  //
  // Description:
  //      Builds the NT Exception record, and calls the NT runtime to initiate
  //      exception processing.
  //
  //      Why is pThrowInfo defined as _ThrowInfo?  Because _ThrowInfo is secretly
  //      snuck into the compiler, as is the prototype for _CxxThrowException, so
  //      we have to use the same type to keep the compiler happy.
  //
  //      Another result of this is that _CRTIMP can't be used here.  Instead, we
  //      synthesisze the -export directive below.
  //
  // Returns:
  //      NEVER.  (until we implement resumable exceptions, that is)
  //
  
  // We want double underscore for CxxThrowException for ARM CE only
  __declspec(noreturn) extern "C" void __stdcall
  #if !defined(_M_ARM) || defined(_M_ARM_NT)
  _CxxThrowException(
  #else
  __CxxThrowException(
  #endif
          void*           pExceptionObject,   // The object thrown
          _ThrowInfo*     pThrowInfo          // Everything we need to know about it
  ) {
          EHTRACE_ENTER_FMT1("Throwing object @ 0x%p", pExceptionObject);
  
          static const EHExceptionRecord ExceptionTemplate = { // A generic exception record
              EH_EXCEPTION_NUMBER,            // Exception number
              EXCEPTION_NONCONTINUABLE,       // Exception flags (we don't do resume)
              NULL,                           // Additional record (none)
              NULL,                           // Address of exception (OS fills in)
              EH_EXCEPTION_PARAMETERS,        // Number of parameters
              {   EH_MAGIC_NUMBER1,           // Our version control magic number
                  NULL,                       // pExceptionObject
                  NULL,
  #if _EH_RELATIVE_OFFSETS
                  NULL                        // Image base of thrown object
  #endif
              }                      // pThrowInfo
          };
          EHExceptionRecord ThisException = ExceptionTemplate;    // This exception
  
          ThrowInfo* pTI = (ThrowInfo*)pThrowInfo;
          if (pTI &amp;&amp; (THROW_ISWINRT( (*pTI) ) ) )
          {
              ULONG_PTR *exceptionInfoPointer = *reinterpret_cast&lt;ULONG_PTR**&gt;(pExceptionObject);
              exceptionInfoPointer--; // The pointer to the ExceptionInfo structure is stored sizeof(void*) infront of each WinRT Exception Info.
  
              WINRTEXCEPTIONINFO* wei = reinterpret_cast&lt;WINRTEXCEPTIONINFO*&gt;(*exceptionInfoPointer);
              pTI = wei-&gt;throwInfo;
          }
  
          //
          // Fill in the blanks:
          //
          ThisException.params.pExceptionObject = pExceptionObject;
          ThisException.params.pThrowInfo = pTI;
  #if _EH_RELATIVE_OFFSETS
          PVOID ThrowImageBase = RtlPcToFileHeader((PVOID)pTI, &amp;ThrowImageBase);
          ThisException.params.pThrowImageBase = ThrowImageBase;
  #endif
  
          //
          // If the throw info indicates this throw is from a pure region,
          // set the magic number to the Pure one, so only a pure-region
          // catch will see it.
          //
          // Also use the Pure magic number on Win64 if we were unable to
          // determine an image base, since that was the old way to determine
          // a pure throw, before the TI_IsPure bit was added to the FuncInfo
          // attributes field.
          //
          if (pTI != NULL)
          {
              if (THROW_ISPURE(*pTI))
              {
                  ThisException.params.magicNumber = EH_PURE_MAGIC_NUMBER1;
              }
  #if _EH_RELATIVE_OFFSETS
              else if (ThrowImageBase == NULL)
              {
                  ThisException.params.magicNumber = EH_PURE_MAGIC_NUMBER1;
              }
  #endif
          }
  
          //
          // Hand it off to the OS:
          //
  
          EHTRACE_EXIT;
  #if defined(_M_X64) &amp;&amp; defined(_NTSUBSET_)
          RtlRaiseException( (PEXCEPTION_RECORD) &amp;ThisException );
  #else
          RaiseException( ThisException.ExceptionCode,
                          ThisException.ExceptionFlags,
                          ThisException.NumberParameters,
                          (PULONG_PTR)&amp;ThisException.params );
  #endif
  }
  </code></pre>
  
  <p><strong>EDIT 3:</strong></p>
  
  <p>When it is compiling appears this things down there right before the error!</p>
  
  <p><img src="https://i.stack.imgur.com/qGlFu.png" alt="enter image description here"></p>