Use OpenCV for image creation, saving, and replication _opencv

Source: Internet
Author: User

Routines from the speech "using OpenCV for image processing"

/************************************************** * cvloadimage, Cvsaveimage, Cvcreateimage, cvcopy and Image Display Example * * * / /********************************************************** * OpenCV Example * by Shiqi Yu 2006 ********************************************************************* **/  #include "cv.h" #include "highgui.h"   int main (int argc, char** argv) {iplimage* pimg;//Declaration Iplimage Point
      Pin  //load image, force conversion to gray if (argc = = 3 && (pimg = Cvloadimage (argv[1), 0))!= 0) { 
      iplimage* PImg2 = Cvcreateimage (Cvgetsize (pimg), pimg->depth, pimg->nchannels);
Cvcopy (pimg, PImg2, NULL);   Cvsaveimage (argv[2], PIMG2)//write image to file   Cvnamedwindow ("image", 1);//Create Window Cvshowimage ("Ima GE ", pimg);//Display image   Cvwaitkey (0); Wait for button   Cvdestroywindow ("Image");//Destroy Window Cvreleaseimage (&pimg);
Releasing images      Cvreleaseimage (&PIMG2);
    Release image return 0;
}   return-1; }
Edit Python version
#-*-Coding:utf-8-*-
###########################################################
# OpenCV Example
# #
Cvloadimage, Cvsaveimage, Cvcreateimage, cvcopy
# and image display Examples
# by
Chaishushan
2008 ########### ################################################ import
sys
# imports OpenCV module
from OPENCV.CV Import * from
Opencv.highgui import *
if __name__ = = ' __main__ ':
    If Len (sys.argv) = = 3:
        # Load image, Force conversion to gray
        pimg = Cvloadimage (sys.argv[1], 0)
        if not pImg:sys.exit ( -1)

  # Create the same size figure small
        pImg2 = Cvcreateimage (Cvgetsize (pimg), pimg.depth, pimg.nchannels)
        # Copy Image
        cvcopy (pimg, PImg2, None)
        # Write image to file
        cvsaveimage (sys.argv[2], pImg2)
        # Create window
        cvnamedwindow ("Mywin")
        # Display Image
        Cvshowimage ("Mywin", pimg)
        cvwaitkey (0)

Note: The python version is rewritten by chai2010. Edit python2.7-opencv2.2 version

#-*-Coding:utf-8-*-
' Created on
2011-8-17
@author: Sunny ' '
# import OPENCV module Imports
CV
Import sys
if __name__ = = ' __main__ ':
        # Load image, Force convert to gray
        pimg = cv. LoadImage ("lena.jpg")
        # creates the same sized figure of the small
        pImg2 = cv. CreateImage (CV. GetSize (pimg), pimg.depth, pimg.nchannels)
        # Copy the image
        cv. Copy (pimg, PImg2, None)
        # writes the image to the file
        cv. SaveImage ("Lena1.jpg", PImg2)
        # Create a window
        cv. Namedwindow ("Mywin")
        # Displays the image
        cv. ShowImage ("Mywin", pimg)
        CV. Waitkey (0)

Note: The python2.7-opencv2.2 version is rewritten by sunny2020.


from:http://wiki.opencv.org.cn/index.php/%e5%9b%be%e5%83%8f%e5%88%9b%e5%bb%ba%e3%80%81%e4%bf%9d%e5%ad%98%e5%92 %8c%e5%a4%8d%e5%88%b6

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.