Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7627093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:24:50+00:00 2026-05-31T05:24:50+00:00

I am using opencv with python. I wanted to do an cv2.imwrte: cv2.imwrite(‘myimage.png’, my_im)

  • 0

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 recognize the params constants:

cv2.imwrite('myimage.png', my_im, cv2.CV_IMWRITE_PNG_COMPRESSION, 0)

It cannot find CV_IMWRITE_PNG_COMPRESSION at all. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:24:51+00:00Added an answer on May 31, 2026 at 5:24 am

    I can’t find key CV_XXXXX in the cv2 module:

    1. Try cv2.XXXXX
    2. Failing that, use cv2.cv.CV_XXXXX

    In your case, cv2.cv.CV_IMWRITE_PNG_COMPRESSION.


    More info.

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A few days back, I started using new OpenCV-Python interface, cv2 . My question
I'm using the Python bindings to OpenCV. If I pass a nonexistent (or bad)
I am using OpenCV library. It doesn't have a modulo operator that can be
I'm doing background subtraction using opencv. The problem is the foreground object is not
I am building an application using OpenCV that uses the webcam and runs some
I'm implementing the component labelling algorithm as in this paper using python and opencv.
I am using openCV python bindings. I am trying to show the output image
I am trying to implement a Digit Recognition OCR in OpenCV-Python (cv2). It is
Im using opencv 2.0 with cvblob.h in VS2010 and I made a program that
What is the most efficient way using opencv and python to locate and return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.