I am using opencv with python. I wanted to do an cv2.imwrte:
cv2.imwrite(\'myimage.png\', my_im)
The only problem is that opencv does not r
the compression style is automatically chosen from the file extension. see the cv2.imwrite help here.
however you might still be interested to know all the possible flags used by all the possible functions in cv2 and cv modules.
look for cv2.txt and cv.txt on your computer. they will be where the opencv modules are installed. at the bottom of those text files are a list of the flags used by the respective modules.
just in case you don't find them, you can download the ones i have from here, though they are from august 2011:
I can't find key CV_XXXXX
in the cv2
module:
cv2.XXXXX
cv2.cv.CV_XXXXX
In your case, cv2.cv.CV_IMWRITE_PNG_COMPRESSION
.
The docs for OpenCV (cv2 interface) are a bit confusing.
Usually parameters that look like CV_XXXX
are actually cv2.XXXX
.
I use the following to search for the relevant cv2
constant name. Say I was looking for CV_MORPH_DILATE
. I'll search for any constant with MORPH
in it:
import cv2
nms = dir(cv2) # list of everything in the cv2 module
[m for m in nms if 'MORPH' in m]
# ['MORPH_BLACKHAT', 'MORPH_CLOSE', 'MORPH_CROSS', 'MORPH_DILATE',
# 'MORPH_ELLIPSE', 'MORPH_ERODE', 'MORPH_GRADIENT', 'MORPH_OPEN',
# 'MORPH_RECT', 'MORPH_TOPHAT']
From this I see that MORPH_DILATE
is what I'm looking for.
However, sometimes the constants have not been moved from the cv
interface to the cv2
interface yet.
In that case, you can find them under cv2.cv.CV_XXXX
.
So, I looked for IMWRITE_PNG_COMPRESSION
for you and couldn't find it (under cv2....
), and so I looked under cv2.cv.CV_IMWRITE_PNG_COMPRESSION
, and hey presto! It's there:
>>> cv2.cv.CV_IMWRITE_PNG_COMPRESSION
16
in fact, with cv2 style API, this constant is replaced with cv2.IMWRITE_PNG_COMPRESSION
.
Expanding on mathematical.coffee to ignore case and look in both namespaces:
import cv2
import cv2.cv as cv
nms = [(n.lower(), n) for n in dir(cv)] # list of everything in the cv module
nms2 = [(n.lower(), n) for n in dir(cv2)] # list of everything in the cv2 module
search = 'imwrite'
print "in cv2\n ",[m[1] for m in nms2 if m[0].find(search.lower())>-1]
print "in cv\n ",[m[1] for m in nms if m[0].find(search.lower())>-1]
>>>
in cv2
['imwrite']
in cv
['CV_IMWRITE_JPEG_QUALITY', 'CV_IMWRITE_PNG_COMPRESSION', 'CV_IMWRITE_PXM_BINARY']
>>>
Hopefully this problem will go away in some later release of cv2...