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

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript