python中使用opencv_如何在python中使用opencv处理图像?

这是固定密码。请参见内联注释。长话短说:你的数据类型是错误的。阅读API。try:

from opencv.cv import *

from opencv.highgui import *

except:

#

# Different OpenCV installs name their packages differently.

#

from cv import *

if __name__ == '__main__':

import sys

#

# 1 = Force the image to be loaded as RGB

#

img = LoadImage (sys.argv[1], 1)

NamedWindow ('img')

ShowImage ('img', img)

WaitKey ()

#

# Canny and Harris expect grayscale (8-bit) input.

# Convert the image to grayscale. This is a two-step process:

# 1. Convert to 3-channel YCbCr image

# 2. Throw away the chroma (Cb, Cr) and keep the luma (Y)

#

yuv = CreateImage(GetSize(img), 8, 3)

gray = CreateImage(GetSize(img), 8, 1)

CvtColor(img, yuv, CV_BGR2YCrCb)

Split(yuv, gray, None, None, None)

canny = CreateImage(GetSize(img), 8, 1)

Canny(gray, canny, 50, 200)

NamedWindow ('canny')

ShowImage ('canny', canny)

WaitKey()

#

# The Harris output must be 32-bit float.

#

harris = CreateImage (GetSize(img), IPL_DEPTH_32F, 1)

CornerHarris(gray, harris, 5, 5, 0.1)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值