【计算机视觉】【OpenCV】OpenCV 3.X第一个python示例

查看opencv的版本

确认opencv版本的重要性:因为opencv版本不同,内部封装宏不同。比如opencv 2.x和opencv 3.x的imread函数入参就不同:

        #img = cv2.imread(sys.argv[1], cv2.CV_LOAD_IMAGE_UNCHANGED) #opencv 2.X时用cv2.CV_LOAD_IMAGE_UNCHANGED
        img = cv2.imread(sys.argv[1], cv2.IMREAD_ANYCOLOR)          #opencv 3.X时用cv.IMREAD_ANCOLOR
import cv2
cv2.__version__

代码

    1)网盘下载:链接:https://pan.baidu.com/s/1S8r1ZBrJPXyRWSpOmhByyg 密码:l2kb

    代码说明

# -*- coding: utf-8 -*-
"""
Created on Sun Mar 18 18:57:44 2018

@author: tom
"""

import cv2
import sys

#main function
if __name__ =='__main__':
    if len(sys.argv) > 1:
        #input image
        #img = cv2.imread(sys.argv[1], cv2.CV_LOAD_IMAGE_UNCHANGED) #opencv 2.X时用cv2.CV_LOAD_IMAGE_UNCHANGED
        img = cv2.imread(sys.argv[1], cv2.IMREAD_ANYCOLOR)          #opencv 3.X时用cv.IMREAD_ANCOLOR
    else:
        print('Usage:python ex2_first_opencv2.py imageFile')
    #show image
    cv2.imshow('image', img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

waitKe(0)阻塞等待用户输入任意键

destroyAllWindows()关闭所有窗口

执行

1)代码py文件所在文件夹上shift+鼠标右键---->“在此处打开命令行窗口(W)”--->在打开的cmd窗口上输入python--->输入空格---->将py文件拖入窗口内--->输入空格---->将lena.jpg拖入窗口--->然后按下enter键。

进过以上步骤就会打开lena.jpg文件,如下图所示,在英文模式下然后按下任意键退出窗口


(end)

Computer vision is found everywhere in modern technology. OpenCV for Python enables us to run computer vision algorithms in real time. With the advent of powerful machines, we are getting more processing power to work with. Using this technology, we can seamlessly integrate our computer vision applications into the cloud. Web developers can develop complex applications without having to reinvent the wheel. This book is a practical tutorial that covers various examples at different levels, teaching you about the different functions of OpenCV and their actual implementations. Who this book is for This book is intended for Python developers who are new to OpenCV and want to develop computer vision applications with OpenCV and Python. This book is also useful for generic software developers who want to deploy computer vision applications on the cloud. It would be helpful to have some familiarity with basic mathematical concepts such as vectors and matrices. What this book covers Chapter 1, Applying Geometric Transformations to Images, explains how to apply geometric transformations to images. In this chapter, we will discuss affine and projective transformations and see how we can use them to apply cool geometric effects to photos. The chapter will begin with the procedure of installing OpenCV-Python on multiple platforms, such as Mac OS X, Linux, and Windows. You will also learn how to manipulate an image in various ways, such as resizing and changing color spaces. Chapter 2, Detecting Edges and Applying Image Filters, shows how to use fundamental image- processing operators and how we can use them to build bigger projects. We will discuss why we need edge detection and how it can be used in various different ways in computer vision applications. We will discuss image filtering and how we can use it to apply various visual effects to photos. Chapter 3, Cartoonizing an Image, shows how to cartoonize a given image using image filters and other transformations. We will see how to use the webcam to capture a live video stream. We will discuss how to build a real-time application, where we extract information from each frame in the stream and display the result. Preface Chapter 4, Detecting and Tracking Different Body Parts, shows how to detect and track faces in a live video stream. We will discuss the face detection pipeline and see how we can use it to detect and track different parts of the face, such as eyes, ears, mouth, and nose. Chapter 5, Extracting Features from an Image, is about detecting the salient points (called keypoints) in an image. We will discuss why these salient points are important and how we can use them to understand the image's content. We will talk about the different techniques that can be used to detect salient points and extract features from an image. Chapter 6, Seam Carving, shows how to do content-aware image resizing. We will discuss how to detect interesting parts of an image and see how we can resize a given image without deteriorating those interesting parts. Chapter 8, Detecting Shapes and Segmenting an Image, shows how to perform image segmentation. We will discuss how to partition a given image into its constituent parts in the best possible way. You will also learn how to separate the foreground from the background in an image. Chapter 8, Object Tracking, shows you how to track different objects in a live video stream. At the end of this chapter, you will be able to track any object in a live video stream that is captured through the webcam. Chapter 9, Object Recognition, shows how to build an object recognition system. We will discuss how to use this knowledge to build a visual search engine. Chapter 10, Augmented Reality, shows how to build an augmented reality application. By the end of this chapter, you will be able to build a fun augmented reality project using the webcam. Chapter 11, Machine Learning by Artificial Neural Network, shows how to build advanced image classifiers and object recognition using the latest OpenCV implementations. By the end of this chapter, you will be able to understand how neural networks work and how to apply them to machine learning to build advance images tools.
原pdf书签不正常(非发行版pdf),2016.02.16本人对书签进行了修正。 Paperback: 296 pages Publisher: Packt Publishing - ebooks Account (September 2015) Language: English ISBN-10: 1785283936 ISBN-13: 978-1785283932 Build real-world computer vision applications and develop cool demos using OpenCV for Python About This Book Learn how to apply complex visual effects to images using geometric transformations and image filters Extract features from an image and use them to develop advanced applications Build algorithms to help you understand the image content and perform visual searches Who This Book Is For This book is intended for Python developers who are new to OpenCV and want to develop computer vision applications with OpenCV-Python. This book is also useful for generic software developers who want to deploy computer vision applications on the cloud. It would be helpful to have some familiarity with basic mathematical concepts such as vectors, matrices, and so on. What You Will Learn Apply geometric transformations to images, perform image filtering, and convert an image into a cartoon-like image Detect and track various body parts such as the face, nose, eyes, ears, and mouth Stitch multiple images of a scene together to create a panoramic image Make an object disappear from an image Identify different shapes, segment an image, and track an object in a live video Recognize an object in an image and build a visual search engine Reconstruct a 3D map from images Build an augmented reality application
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值