我正在尝试使用opencv v 2.1创建一个图像,但是我得到了这个错误:image = cv.CreateImage((w,h),no_of_bits,channels)AttributeError:'module'对象没有属性'CreateImage'
代码是
#!/usr/bin/python
import cv
from opencv import *
from opencv.cv import *
from opencv.highgui import *
import sys
import PIL
w=500
h=500
no_of_bits=8
channels=3
image=cv.CreateImage((w,h),no_of_bits,channels)
cv.ShowImage('WindowName',image)
cvWaitKey()
Run Code Online (Sandbox Code Playgroud)
Kim*_*mmo 20
由于没有很多很好的例子如何使用cv2创建填充颜色的新空白图像,这里有一个:
创建某些(R,G,B)颜色的OpenCV图像:
import cv2
import numpy as np
def create_blank(width, height, rgb_color=(0, 0, 0)):
"""Create new image(numpy array) filled with certain color in RGB"""
# Create black blank image
image = np.zeros((height, width, 3), np.uint8)
# Since OpenCV uses BGR, convert the color first
color = tuple(reversed(rgb_color))
# Fill image with color
image[:] = color
return image
# Create new blank 300x300 red image
width, height = 300, 300
red = (255, 0, 0)
image = create_blank(width, height, rgb_color=red)
cv2.imwrite('red.jpg', image)
Run Code Online (Sandbox Code Playgroud)
你正在写名称空间.只使用而import cv
不是其他的.
>>> import cv
>>> w=500
>>> no_of_bits=8
>>> channels=3
>>> h=500
>>> image=cv.CreateImage((w,h),no_of_bits,channels)
>>> print image
<iplimage(nChannels=3 width=500 height=500 widthStep=1500 )>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
24748 次 |
最近记录: |