64826

Create instances of class Rect from opencv 3 in Python

Question:

I would like to know how I can get an opencv rect object by providing two Points. The c++ version provides this datastructre.

<a href="http://docs.opencv.org/java/2.4.9/org/opencv/core/Rect.html" rel="nofollow">http://docs.opencv.org/java/2.4.9/org/opencv/core/Rect.html</a>

I cant find a way to instantiate rects in python. I tried cv2.Rect(p1,p2) but this method seems not be existent. Is it even possible?

Thanks in adavance :)

Answer1:

Look for example at this tutorial face detection <a href="http://docs.opencv.org/trunk/d7/d8b/tutorial_py_face_detection.html" rel="nofollow">http://docs.opencv.org/trunk/d7/d8b/tutorial_py_face_detection.html</a> and you'll see that in Python opencv bindings rectangles are tuples/lists of the four coordinates - the results of, for example, faceCascade.detectMultiScale is a list of these - basically, use normal Python capabilities to manage them.

I guess you'll have to write your own overlap/area/contains functions - not terribly diificult - or see other answers here, for example <a href="https://stackoverflow.com/questions/25068538/intersection-and-difference-of-two-rectangles/25068722#25068722" rel="nofollow">Intersection and difference of two rectangles</a>

UPDATE - my bad, the rectangles returned by detectMultiScale are (x,y,w,h)

Recommend

  • Any way to speed up Python and Pygame?
  • Showing text on mouseover - Title element inconsistent, title attribute does nothing
  • Add 'fake' antialiasing to rotated rectangle
  • Need to track PC down times using PHP ping and display time down D:HH:MM
  • Why does EF Core always return -1 with this stored procedure?
  • exceptions.TypeError: src is not a numpy array, neither a scalar
  • Face aligment check with DLIB
  • OpenCV's video capture not returning an image
  • lights animation in objective-c
  • Error while trying to upload file using kairos
  • Pass code to a method as an argument
  • plot if col A has substring
  • com.jcraft.jsch.JSchException: Algorithm negotiation fail
  • sort decimal in php or mysql
  • how to compile code from svn into jar file?
  • How to realize with WinForms in C# something like an image with map areas in a homepage (at hooverin
  • C++ face detection/recognition implementations
  • Git Merge Adds New File Instead of Conflict Markers - CONFLICT (rename/add)
  • Unable to generate call to cell phone using asterisk
  • JPS useBean with HashMap
  • Cannot instantiate the type Image java?
  • How to change the margins of a correlation matrix plot
  • Efficiently getting XML into Elasticsearch
  • How to initialize context? [closed]
  • Initialization section of the package
  • Negating Regex PO BOX
  • Adding a model to a Marionette CollectionView's collection doesn't trigger onItemAdd callb
  • import scipy.sparse failed
  • During installation of Django, why do I keep getting ImportError: No module named django?
  • where do I find the xml.dom python package for the python-2.6.0-8.9.28 and I have a suse/x86_64 vers
  • Python pickle not one-to-one: different pickles give same object
  • Trying to switch camera back to front but getting exception
  • SVN: Merging two branches together
  • Free memory of cv::Mat loaded using FileStorage API
  • Angular 2 constructor injection vs direct access
  • How can I remove ASP.NET Designer.cs files?
  • python draw pie shapes with colour filled
  • Is there any way to bind data to data.frame by some index?
  • Programmatically clearing map cache
  • How can i traverse a binary tree from right to left in java?