Python OpenCV2 (cv2) wrapper to get image size?

cv2 uses numpy for manipulating images, so the proper and best way to get the size of an image is using numpy.shape. Assuming you are working with BGR images, here is an example: In case you were working with binary images, img will have two dimensions, and therefore you must change the code to: height, … Read more

Why are there two different getline() functions (if indeed there are)?

Bear in mind that the Standard library is composed from 3 (main) parts: IOStream, String and STL, plus some tossed in goodies and the C-headers. I don’t see anything weird in having those parts loosely coupled (though I wish it was not the case). Other incongruities include: std::string::length vs std::string::size, the latter having been added for interface compatibility … Read more

hat’s a clean way to stop mongod on Mac OS X?

It’s probably because launchctl is managing your mongod instance. If you want to start and shutdown mongod instance, unload that first: Then start mongod manually: You can find your mongod.conf location from ~/Library/LaunchAgents/org.mongodb.mongod.plist. After that, db.shutdownServer() would work just fine. Added Feb 22 2014: If you have mongodb installed via homebrew, homebrew actually has a handy brew services command. To … Read more

Correct modification of state arrays in React.js

The React docs says: Treat this.state as if it were immutable. Your push will mutate the state directly and that could potentially lead to error prone code, even if you are “resetting” the state again afterwards. F.ex, it could lead to that some lifecycle methods like componentDidUpdate won’t trigger. The recommended approach in later React … Read more

Test Average and Grade – Python

To have it print the letter grade as a user enters a score you can do something like: The letter grade problem was that you were using total which was all the grades added up (hopefully more than 100 if you got at least a 20 on all 5 assignments), so it would always default … Read more

Change directory command in Docker?

You can run a script, or a more complex parameter to the RUN. Here is an example from a Dockerfile I’ve downloaded to look at previously: Because of the use of ‘&&’, it will only get to the final ‘pip install’ command if all the previous commands have succeeded. In fact, since every RUN creates … Read more