I feel obligated to answer my question as I figured out the problem after a lot of wasted time. I had originally compiled OpenCV using Visual Studio 2010 and had been working fine. About a month ago, I needed to develop something using C++-11 features due to a collaboration and so, I installed Visual 2013 but did not recompile OpenCV to work with 2013. Things had been working fine till I encountered this issue with findContours even though I did not use any C++-11 features in this code. I compiled my code using 2010 and things worked as expected. Lesson learned: do not mix code from different versions of Visual Studio, even on the same machine. Sorry to waste your time.