How to fix OpenCV Numpy Error, object is not iterableHow to sort a list of objects based on an attribute of the objects?How to know if an object has an attribute in PythonHow to remove items from a list while iterating?How to iterate through two lists in parallel?In Python, how do I determine if an object is iterable?TypeError: 'NoneType' object is not iterable in PythonHow to fix “Attempted relative import in non-package” even with __init__.pyHow to iterate over rows in a DataFrame in Pandas?Extracting X coordinate from numpy arraychecking the Colors Opencv Python

PDF page & word count, recursive searching of directory tree, output to excel

Why does every calorie tracking app give a different target calorie count for the same goals?

"was fiction" vs "were fictions"

Proof of Isoperimetric Inequality using Curve Shortening Flow

How to compare the ls output of two folders to find a missing directory?

A horrible Stockfish chess engine evaluation

How to tell someone I'd like to become friends without letting them think I'm romantically interested in them?

Is there a strong legal guarantee that the U.S. can give to another country that it won't attack them?

What's it called when the bad guy gets eaten?

What happens to unproductive professors?

Distinguish the explanations of Galadriel's test in LotR

Why is Nibbana referred to as "The destination and the path leading to the destination"?

When did "&" stop being taught alongside the alphabet?

pattern recognition riddle

What is a "Lear Processor" and how did it work?

Why do you use the "park" gear to park a car and not only the handbrake?

Is this a reference to the film Alien in the novel 2010 Odyssey Two?

What is the right approach to quit a job during probation period for a competing offer?

Swapping "Good" and "Bad"

Addressing unnecessary daily meetings with manager?

What would +1/+2/+3 items be called in game?

LED glows slightly during soldering

Why is the ladder of the LM always in the dark side of the LM?

What is the parallel of Day of the Dead with Stranger things?



How to fix OpenCV Numpy Error, object is not iterable


How to sort a list of objects based on an attribute of the objects?How to know if an object has an attribute in PythonHow to remove items from a list while iterating?How to iterate through two lists in parallel?In Python, how do I determine if an object is iterable?TypeError: 'NoneType' object is not iterable in PythonHow to fix “Attempted relative import in non-package” even with __init__.pyHow to iterate over rows in a DataFrame in Pandas?Extracting X coordinate from numpy arraychecking the Colors Opencv Python






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm following a guide to develop a motion detection security feed and have run into an issue. The author of the tutorial had no issues, but I do.



'''The full code can be found here: https://github.com/ncorbuk/Python-Motion-Detection-system/blob/master/motion_detection.py
'''



I have already tried the option of adding,



" for c in cnt or []: " - This got me further into running the application where I could see the camera screens, however as soon as motion is detected the application crashes and provides the following numpy error:




The truth value of an array with more than one element is ambiguous.
Use a.any() or a.all()




for c in cnt:
if (cv2.contourArea(c) > 800):
(x, y, w, h) = cv2.boundingRect(c)

cv2.rectangle(frame, (x,y), (x+w, y+h), (0, 255, 0), 2)

text = 'Occupied'

else:
pass


The expected output, if you have a webcam;
When motion is detected a green rectangle will follow the moving pixels and change the mode from Unoccupied to Occupied, in real time; with no errors.










share|improve this question
























  • What version of OpenCV are you using?

    – alkasm
    Mar 26 at 0:42











  • @AlexanderReynolds I'm using opencv-python==4.0.0.21

    – Devshades
    Mar 26 at 0:52

















0















I'm following a guide to develop a motion detection security feed and have run into an issue. The author of the tutorial had no issues, but I do.



'''The full code can be found here: https://github.com/ncorbuk/Python-Motion-Detection-system/blob/master/motion_detection.py
'''



I have already tried the option of adding,



" for c in cnt or []: " - This got me further into running the application where I could see the camera screens, however as soon as motion is detected the application crashes and provides the following numpy error:




The truth value of an array with more than one element is ambiguous.
Use a.any() or a.all()




for c in cnt:
if (cv2.contourArea(c) > 800):
(x, y, w, h) = cv2.boundingRect(c)

cv2.rectangle(frame, (x,y), (x+w, y+h), (0, 255, 0), 2)

text = 'Occupied'

else:
pass


The expected output, if you have a webcam;
When motion is detected a green rectangle will follow the moving pixels and change the mode from Unoccupied to Occupied, in real time; with no errors.










share|improve this question
























  • What version of OpenCV are you using?

    – alkasm
    Mar 26 at 0:42











  • @AlexanderReynolds I'm using opencv-python==4.0.0.21

    – Devshades
    Mar 26 at 0:52













0












0








0








I'm following a guide to develop a motion detection security feed and have run into an issue. The author of the tutorial had no issues, but I do.



'''The full code can be found here: https://github.com/ncorbuk/Python-Motion-Detection-system/blob/master/motion_detection.py
'''



I have already tried the option of adding,



" for c in cnt or []: " - This got me further into running the application where I could see the camera screens, however as soon as motion is detected the application crashes and provides the following numpy error:




The truth value of an array with more than one element is ambiguous.
Use a.any() or a.all()




for c in cnt:
if (cv2.contourArea(c) > 800):
(x, y, w, h) = cv2.boundingRect(c)

cv2.rectangle(frame, (x,y), (x+w, y+h), (0, 255, 0), 2)

text = 'Occupied'

else:
pass


The expected output, if you have a webcam;
When motion is detected a green rectangle will follow the moving pixels and change the mode from Unoccupied to Occupied, in real time; with no errors.










share|improve this question
















I'm following a guide to develop a motion detection security feed and have run into an issue. The author of the tutorial had no issues, but I do.



'''The full code can be found here: https://github.com/ncorbuk/Python-Motion-Detection-system/blob/master/motion_detection.py
'''



I have already tried the option of adding,



" for c in cnt or []: " - This got me further into running the application where I could see the camera screens, however as soon as motion is detected the application crashes and provides the following numpy error:




The truth value of an array with more than one element is ambiguous.
Use a.any() or a.all()




for c in cnt:
if (cv2.contourArea(c) > 800):
(x, y, w, h) = cv2.boundingRect(c)

cv2.rectangle(frame, (x,y), (x+w, y+h), (0, 255, 0), 2)

text = 'Occupied'

else:
pass


The expected output, if you have a webcam;
When motion is detected a green rectangle will follow the moving pixels and change the mode from Unoccupied to Occupied, in real time; with no errors.







python opencv typeerror nonetype






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 0:05









Alex W

28.6k7 gold badges68 silver badges85 bronze badges




28.6k7 gold badges68 silver badges85 bronze badges










asked Mar 25 at 23:59









DevshadesDevshades

32 bronze badges




32 bronze badges












  • What version of OpenCV are you using?

    – alkasm
    Mar 26 at 0:42











  • @AlexanderReynolds I'm using opencv-python==4.0.0.21

    – Devshades
    Mar 26 at 0:52

















  • What version of OpenCV are you using?

    – alkasm
    Mar 26 at 0:42











  • @AlexanderReynolds I'm using opencv-python==4.0.0.21

    – Devshades
    Mar 26 at 0:52
















What version of OpenCV are you using?

– alkasm
Mar 26 at 0:42





What version of OpenCV are you using?

– alkasm
Mar 26 at 0:42













@AlexanderReynolds I'm using opencv-python==4.0.0.21

– Devshades
Mar 26 at 0:52





@AlexanderReynolds I'm using opencv-python==4.0.0.21

– Devshades
Mar 26 at 0:52












1 Answer
1






active

oldest

votes


















1














In Opencv4.0, findContour() returns only 2 values, contours and hierachy. So in the line 57 in motion_detection.py you have to change



cnt = cv2.findContours(dilate_image.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[1]



to



cnt = cv2.findContours(dilate_image.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0].






share|improve this answer























  • Thank you so much @Ha Bom, your answer has solved my problem!

    – Devshades
    Mar 26 at 1:10










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348047%2fhow-to-fix-opencv-numpy-error-object-is-not-iterable%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














In Opencv4.0, findContour() returns only 2 values, contours and hierachy. So in the line 57 in motion_detection.py you have to change



cnt = cv2.findContours(dilate_image.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[1]



to



cnt = cv2.findContours(dilate_image.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0].






share|improve this answer























  • Thank you so much @Ha Bom, your answer has solved my problem!

    – Devshades
    Mar 26 at 1:10















1














In Opencv4.0, findContour() returns only 2 values, contours and hierachy. So in the line 57 in motion_detection.py you have to change



cnt = cv2.findContours(dilate_image.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[1]



to



cnt = cv2.findContours(dilate_image.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0].






share|improve this answer























  • Thank you so much @Ha Bom, your answer has solved my problem!

    – Devshades
    Mar 26 at 1:10













1












1








1







In Opencv4.0, findContour() returns only 2 values, contours and hierachy. So in the line 57 in motion_detection.py you have to change



cnt = cv2.findContours(dilate_image.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[1]



to



cnt = cv2.findContours(dilate_image.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0].






share|improve this answer













In Opencv4.0, findContour() returns only 2 values, contours and hierachy. So in the line 57 in motion_detection.py you have to change



cnt = cv2.findContours(dilate_image.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[1]



to



cnt = cv2.findContours(dilate_image.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0].







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 26 at 1:06









Ha BomHa Bom

1,7152 gold badges6 silver badges20 bronze badges




1,7152 gold badges6 silver badges20 bronze badges












  • Thank you so much @Ha Bom, your answer has solved my problem!

    – Devshades
    Mar 26 at 1:10

















  • Thank you so much @Ha Bom, your answer has solved my problem!

    – Devshades
    Mar 26 at 1:10
















Thank you so much @Ha Bom, your answer has solved my problem!

– Devshades
Mar 26 at 1:10





Thank you so much @Ha Bom, your answer has solved my problem!

– Devshades
Mar 26 at 1:10








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348047%2fhow-to-fix-opencv-numpy-error-object-is-not-iterable%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현