我試圖旋轉從實時網絡攝像頭的幀圖像,但我得到一些一個錯誤,相同的代碼工作正常,當我使用的系統上的任何保存的圖像,但它不與工作正常網民,在程序中,如果有人能幫助我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