compatibility issue with contourArea in openCV 3
<p>I am trying to do a simple area calculation of contours I get from findContours.
My openCv version is 3.1.0</p>

<p>My code is:</p>

<pre><code>cc = cv2.findContours(im_bw.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.contourArea(cc[0])

error: 'C:\\builds\\master_PackSlaveAddon-win32-vc12-static\\opencv\\modules\\imgproc\\src\\shapedescr.cp...: error: (-215) npoints &gt;= 0 &amp;&amp; (depth == CV_32F || depth == CV_32S) in function cv::contourArea\n'
</code></pre>

<p>Cant seem to solve it, I have a feeling its just typecasting altough I expect the findContours result to match the type of contourArea</p>

<p>Thanks :)</p>

<p>EDIT: turns out I need to take the 2nd argument of findContours</p>

<pre><code> im2, cc, hierarchy = cv2.findContours(im_bw.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
</code></pre>

<p>In Opencv 3 API version the <code>cv2.findContours()</code> returns 3 <a href="http://docs.opencv.org/3.1.0/d4/d73/tutorial_py_contours_begin.html" rel="nofollow">objects</a></p>

<ul>
<li>image </li>
<li>contours</li>
<li>hierarchy</li>
</ul>

<p>So you need to rewrite your statement as:</p>

<pre><code>image, contours, hierarchy = cv2.findContours(im_bw.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
</code></pre>

python opencv opencv3.0