मैं कुछ डिग्री एक छवि को घुमाने की कोशिश कर रहा हूं, फिर इसे विंडो में दिखाएं।पाइथन 2.7.3 + रोटेशन विंडो के बाद ओपनसीवी 2.4 फिट नहीं है छवि
new_width = x * cos angle + y * sin angle
new_height = y * cos angle + x * sin angle
मैं परिणाम उम्मीद कर रहा था नीचे की तरह लग रहे करने के लिए:
मेरा विचार बारी बारी से और फिर गणना वर्ष चौड़ाई और ऊंचाई से नए चौड़ाई और खिड़की की ऊंचाई के साथ एक नई विंडो में यह दिखाने के लिए है
लेकिन यह परिणाम पता चला है इस तरह दिखता है:
और मेरे कोड यहाँ है:
#!/usr/bin/env python -tt
#coding:utf-8
import sys
import math
import cv2
import numpy as np
def rotateImage(image, angel):#parameter angel in degrees
if len(image.shape) > 2:#check colorspace
shape = image.shape[:2]
else:
shape = image.shape
image_center = tuple(np.array(shape)/2)#rotation center
radians = math.radians(angel)
x, y = im.shape
print 'x =',x
print 'y =',y
new_x = math.ceil(math.cos(radians)*x + math.sin(radians)*y)
new_y = math.ceil(math.sin(radians)*x + math.cos(radians)*y)
new_x = int(new_x)
new_y = int(new_y)
rot_mat = cv2.getRotationMatrix2D(image_center,angel,1.0)
print 'rot_mat =', rot_mat
result = cv2.warpAffine(image, rot_mat, shape, flags=cv2.INTER_LINEAR)
return result, new_x, new_y
def show_rotate(im, width, height):
# width = width/2
# height = height/2
# win = cv2.cv.NamedWindow('ro_win',cv2.cv.CV_WINDOW_NORMAL)
# cv2.cv.ResizeWindow('ro_win', width, height)
win = cv2.namedWindow('ro_win')
cv2.imshow('ro_win', im)
if cv2.waitKey() == '\x1b':
cv2.destroyWindow('ro_win')
if __name__ == '__main__':
try:
im = cv2.imread(sys.argv[1],0)
except:
print '\n', "Can't open image, OpenCV or file missing."
sys.exit()
rot, width, height = rotateImage(im, 30.0)
print width, height
show_rotate(rot, width, height)
इस समस्या के लिए अपने कोड नेतृत्व में कुछ बेवकूफ गलतियों होना चाहिए, लेकिन मैं इसे समझ नहीं कर सकते हैं ... और मैं जानता हूँ कि मेरे कोड पर्याप्त pythonic नहीं है :(.. इसके लिए क्षमा करें ..
क्या कोई मेरी मदद कर सकता है?
बेस्ट,
bearzk
संक्षिप्त उत्तर और एनोटेटेड कोड के लिए धन्यवाद। अच्छी तरह से समस्या हल करता है। – leomelzer