我试图旋转从实时网络摄像头的帧图像,但我得到一些一个错误,相同的代码工作正常,当我使用的系统上的任何保存的图像,但它不与工作正常网民,在程序中,如果有人能帮助我thanx提前OpenCV的蟒蛇视频旋转
import cv2.cv as cv
import cv2
import numpy as np
def trackcall(angle):
image0 = rotateImage(image, angle)
cv.ShowImage("imageRotation",image0);
def rotateImage(image, angle):
image0 = image
if hasattr(image, 'shape'):
image_center = tuple(np.array(image.shape)/2)
shape = tuple(image.shape)
elif hasattr(image, 'width') and hasattr(image, 'height'):
image_center = tuple(np.array((image.width/2, image.height/2)))
shape = (image.width, image.height)
else:
raise Exception, 'Unable to acquire dimensions of image for type %s.' % (type(image),)
rot_mat = cv2.getRotationMatrix2D(image_center, angle,1.0)
image = np.asarray(image[:,:])
rotated_image = cv2.warpAffine(image, rot_mat, shape, flags=cv2.INTER_LINEAR)
# Copy the rotated data back into the original image object.
cv.SetData(image0, rotated_image.tostring())
return image0
angle = 720
vc = cv2.VideoCapture(0)
cv.NamedWindow('imageRotation',cv.CV_WINDOW_NORMAL)
cv.NamedWindow('imageMeter',cv.CV_WINDOW_AUTOSIZE)
cv.CreateTrackbar("rotate","imageMeter",360,angle,trackcall)
#image = cv.LoadImage('C:/Users/Public/Pictures/Sample Pictures/Desert.jpg', cv.CV_LOAD_IMAGE_COLOR)
#image0 = rotateImage(image, angle)
if vc.isOpened():
rval = True, image = vc.read()
else:
rval = False
while rval:
image = vc.read()
trackcall(0)
key = cv.WaitKey(0)
if key == 27:
cv.DestroyWindow('imageRotation')
cv.DestroyWindow("imageMeter")
错误是
回溯(最近通话最后一个):
文件“d:\ VideoRotation \ imageRotationWithTrackbar.py “,第44行,在 trackcall(0)
文件 “d:\ VideoRotation \ imageRotationWithTrackbar.py”,第6行,在trackcall image0 = rotateImage(图像,角度)
文件 “d:\ VideoRotation \ imageRotationWithTrackbar.py”,第19行,在rotateImage 引发异常,'无法获取类型%s的图像尺寸。' %(类型(图像),)
例外:无法获取图像的尺寸类型。
是你是正确它给在函数cv2.getRotationMatrix2D的误差(image_center,角度,1.0),该函数取恰好2个参数(3中给出),但在文件中它被具有3个参数的http://文档。 opencv.org/trunk/modules/imgproc/doc/geometric_transformations.html – mohit
我修复了元组问题。但我无法修复旋转功能问题。 cv2.getRotationMatrix2D(image_center,angle,1.0)。做任何其他的功能是通过有,我可以做同样的工作,因为我与cv2.getRotationMatrix2D(...)函数 – mohit
想你可能要问,作为一个新的问题,那可能会得到你更多的响应。关闭这个问题,也许有人可以帮助你的新问题。我的论文需要下周人手不够,所以不幸的是我不能帮你的权利,但如果你阅读文档,并在你的新问题解释正是你想做的事,我相信会有人能够帮助你什么。一旦我有一段时间可用,我也会看看它! – casper