Digging through wxPython sources I found a class wx.ImageHistogram what
looks promising for my purposes. Unfortunately seems like it lost most of
the real functionality comparing with C++ version. Any chances to get it
working like it should?
[I believe it happened due the limited SWIG ability to understand tricky C++
code used in wxWidgets. wxImageHistogramm actually inherited from the
HashMap class but this inheritance is "hidden" because weird macros (like
WX_DECLARE_EXPORTED_HASH_MAP) are used for building wxImageHistogramBase
class.]
Digging through wxPython sources I found a class wx.ImageHistogram what
looks promising for my purposes. Unfortunately seems like it lost most of
the real functionality comparing with C++ version. Any chances to get it
working like it should?
[I believe it happened due the limited SWIG ability to understand tricky C++
code used in wxWidgets. wxImageHistogramm actually inherited from the
HashMap class but this inheritance is "hidden" because weird macros (like
WX_DECLARE_EXPORTED_HASH_MAP) are used for building wxImageHistogramBase
class.]
Correct.
What methods do you think should be exposed?
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Digging through wxPython sources I found a class wx.ImageHistogram what
looks promising for my purposes. Unfortunately seems like it lost most of
the real functionality comparing with C++ version. Any chances to get it
working like it should?
Correct.
What methods do you think should be exposed?
In a case of ImageHistogram I need a method what return count of pixels with
the given key (rgb tripple).
···
-------
image = wx.Image( ... )
hist = wx.ImageHistogram()
image.ComputeHistogram( hist )
key = hist.MakeKey( r,g,b )
-------- so far is all ok ----
now I need something like:
num_pixels = hist[ key ]
or
num_pixels = hist.Count( key )
or
num_pixels = hist.GetCount( key )
or even
num_pixels = hist.Get( key )
--------------------------
On the C++ side this functionality provided by HashMap's operator - there
is no named method for doing it.
I am not familiar with SWIG and don't have an idea how easy or difficult to
expose operator to python. If this is tough, then I would like to see
method (named maybe Count or GetCount or Get) that exposes cpp's
functionality to Python.
Digging through wxPython sources I found a class wx.ImageHistogram what
looks promising for my purposes. Unfortunately seems like it lost most of
the real functionality comparing with C++ version. Any chances to get it
working like it should?
Correct.
What methods do you think should be exposed?
In a case of ImageHistogram I need a method what return count of pixels with
the given key (rgb tripple).
-------
image = wx.Image( ... )
hist = wx.ImageHistogram()
image.ComputeHistogram( hist )
key = hist.MakeKey( r,g,b )
-------- so far is all ok ----
now I need something like:
num_pixels = hist[ key ]
or
num_pixels = hist.Count( key )
or
num_pixels = hist.GetCount( key )
or even
num_pixels = hist.Get( key )
--------------------------
Okay, I've added GetCount and GetCountRGB methods that work like this:
>>> import wx
>>> b = wx.EmptyBitmap(10,10)
>>> dc = wx.BufferedDC(None, b)
>>> dc.SetBackground(wx.Brush("white"))
>>> dc.Clear()
>>> dc.SetPen(wx.Pen("black"))
>>> dc.DrawPoint(5,5)
>>> dc.SetPen(wx.Pen("blue"))
>>> dc.DrawLine(5,0, 10,10)
>>> del dc
>>> i = wx.ImageFromBitmap(b)
>>> h = wx.ImageHistogram()
>>> i.ComputeHistogram(h)
3
>>> h.GetCount(h.MakeKey(0,0,0))
1
>>> h.GetCount(h.MakeKey(255,255,255))
90
>>> h.GetCountRGB(1,1,1)
0
>>> h.GetCountRGB(255,255,255)
90
>>> h.GetCountRGB(0,0,255)
9
Does that meet your needs?
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!