unable to adjust grouping settings in OpenCV's hog.detectMultiScale (python) - python

I am trying to set the grouping settings in the hog.detectMultiScale method from the OpenCV2 library (version 2.4.9).
What happens is that the group_threshold and groupThreshold parameters
are both not recognized in the python binding:
TypeError: 'group_threshold' is an invalid keyword argument for this function
and
TypeError: 'groupThreshold' is an invalid keyword argument for this function
How can I fix this? Is there a way to set this parameter?

group_threshold or groupThreshold does not exist in the Python wrapper of hog.detectMultiScale. Unfortunately, there is no documentation to prove it (typical of OpenCV docs), but there is a related doc in the GPU version of the HOG Descriptor here - http://docs.opencv.org/2.4.9/modules/gpu/doc/object_detection.html#gpu-hogdescriptor-detectmultiscale
However, there seems to be inconsistency with the Python wrapper. If you type in help(cv2.HOGDescriptor().detectMultiScale) in the Python REPL, this is what we get:
detectMultiScale(...)
detectMultiScale(img[, hitThreshold[, winStride[, padding[, scale[,
finalThreshold[, useMeanshiftGrouping]]]]]]) -> foundLocations, foundWeights
If you compare the docs with the Python wrapper, we can clearly see that there are some input parameters are missing, as well as different parameters between them both.
As such, it doesn't look like you can vary this parameter :(. Sorry if this isn't what you wanted to hear! However, this StackOverflow post may prove to be insightful if you want to get it working relatively well:
HOGDescriptor with videos to recognize objects
Good luck!

Related

(variable) annotation in python after method call

While looking through Keras framework I have noticed an interesting style used there.
my_method(some_parameter)(variable_to_call_method_on_apperently)
Could you please provide any insights, what exactly is going on there, and where I can find more information about this?
p.s. I tried to google, but it is not use, since I do not know what to write in search bar.
EDITED: I am confused by the syntax. So, it is not Keras specific. I mentioned Keras trying to make my question more clear.
This is not keras specific. The first call to f(x) returns a value that is callable (that is a function, or an object with a __call__ method) instead of a plain value. Then you go on calling the returned object with the second parentheses arguments.
You might also lookup currying and partial application for related concepts.

pycharm does not show all attributes and methods of a object

When I use Python to write opencv, I have got the image object using the imread method, but when I try to use the object, I cannot see any attribute or method of the method.
Like this
When I use iPython or use the dir() method to check, I can see it
This happens when PyCharm can't guess the type of the object returned by method - imread() in this case. Some methods return different types of object based on the input. You'd have to take a look into opencv source code to see why it isn't clear what the returned type is. Static analysis of the code detects obvious cases.
IPython has already executed the method, so it's clear what type was returned.
One solution, if you know the type returned, is to use type comments like this:
import cv2
import numpy
# I've checked with IPython that the returned object is a `numpy.ndarray` instance
img = cv2.imread('/home/me/Pictures/image.jpg') # type: numpy.ndarray
And then if you type img. you will see
The feauture is described on PEP 0484.
This PEP says it's introduced in Python 3.5. However it might be that PyCharm could handle this simple case in older Python versions than 3.5 but I haven't check.
This PEP describes features of typing module which is not available in older Python versions, so most of the features from this document won't work but I'm not sure if PyCharm is really using typing module to parse type comments or does it natively.

Get types in Python expression using MyPy as library

I have some Python source code, and want to find out the type of a variable. For example given the string
"""
greeting = "Hello"
"""
I want to have get_type('greeting') == str. Or a more complex example:
"""
def test(input: str):
output = len(input)
return str
"""
In pseudocode, I want to be able to do something like:
>>> m = parse_module()
>>> m.functions['test'].locals['output'].get_type()
int
It seems this should be possible with type annotations and MyPy in Python 3, but I can't figure out how. IDEs like VS code have become very good at guessing the types in python code, that is why I'm guessing there must be an exposed way to do this.
There seems to be a module typed-ast, which is also used by MyPy, that gets me part of the way there. However, this does no type inference or propagation, it just gives me the explicit annotations as far as I understand. MyPy as an api, but it only lets you run the checker, and returns the same error messages as the command line tool. I am looking for a way to "reach into" MyPy, and get some of the inferred information out - or some alternative solution I haven't thought of.
Mypy currently has an extremely primitive, bare-bones API, which you can find "documented" within the source code here: https://github.com/python/mypy/blob/master/mypy/api.py. To use it, you essentially need to write your string to a temporary file which you later clean up.
You can perhaps combine this with the reveal_type(...) special directive (and perhaps even the hidden --shadow-file option) to typecheck your string.
The other alternative is to reverse engineer and re-implement pieces of mypy's main.py, essentially hijacking their internal API. I don't really think this will be hard, just somewhat ugly and fragile.
(Note that mypy can theoretically support typechecking arbitrary strings, and the core devs aren't opposed to extending the API for mypy in principle -- it's just that mypy is still under active development which means implementing an API has been very low priority for a while now. And since mypy is still actively being worked on/extended, the devs are somewhat reluctant to commit to implementing a more complex API that they'll subsequently have to support. You can find more context and details regarding the current state of the API in mypy's issue tracker.)

Documentation For Specific Functions in Python

What is the optimal way to get documentation about a specific function in Python? I am trying to download stock price data such that I can view it in my Spyder IDE.
The function I am interested in is:
ystockquote.get_historical_prices
How do I know how many inputs the function takes, the types of inputs it accepts, and the date format for example?
Just finding documentation
I suspect this question was super-downvoted because the obvious answer is to look at the documentation. It depends where your function came from, but googling is typically a good way to find it (I found the class here in a few seconds of googling).
It is also very trivialy to just check the source code
In order to import a function, you need to know where the source file it comes from is; open that file: in python, docstrings are what generate the documentation and can be found in triple-quotes beneath the function declaration. The arguments can be inferred from the function signature, but because python is dynamically typed, any type "requirements" are just suggestions. Some good documenters will provide the optimal types, too.
While "how do I google for documentation" is not a suitable question, the question of how to dynamically infer documentation is more reasonable. The answer is
The help function, built in here
The file __doc__ accessible on any python object, as a string
Using inspection
The question is even more reasonable if you are working with python extensions, like from external packages. I don't if the package you specifically asked about has any of those, but they can be tricky to work with if the authors haven't defined docstrings in the module. The problem is that in these cases, the typing can be rigidly inforced. There is no great way to get the tpye requirements in this case, as inspection will fail. If you can get at the source code, though, (perhaps by googling), this is where the documentation would be provided

What is "Introspection-based code completion"?

I'm looking at various IDEs for python. Looking at the official list the IDEs are categorized based on 'introspection based code completion'.
What does introspection based code completion mean?
Thanks.
It means the IDE uses introspection to figure out what methods and variables are accessible from a given object, then allows quick code completion, usually by providing a list of options after you type a period following a symbol.
Here's an example if WingIDE Pro inaction. Forgive the hastily thrown together image.
You can see that arg1 is being shown as 1 in the first example, as well as the helper showing that it is probably an int.
In the second part, you can see that the IDE is looking through the docstrings for what the method get does, in the requests module.
The second image below shows that the IDE can 'auto-complete' code for you, including showing what it does.

Categories

Resources