⑴ python里如何将视频旋转
好象调用一次主窗口的close似乎就可以。或者是app的close, 或者是destroy或者是terminate,不记得是哪个函数了。 当然你杀掉自己也是可以的。 用kill。 或者是sys.exit也应该可以。
⑵ python做三维图结果怎么用鼠标拖动旋转
旋转视角,要根据三角函数计算的,每转动一个角度都需要重新计算,这些都需要实现,之后根据转动的数值传入进去,计算后,重新画图
⑶ 如何用Python+Pygame旋转图像、灰度图像
‘’‘
2013-7-4
by JavenLee
希望能带给你启发
'''
import Image
img = Image.open(‘origin.png’) # 得到一个图像的实例对象 img
rot_img = img.rotate(270) #顺时针旋转90度
rot_img.save("rot_img.jpg")
x_img=img.transpose(Image.FLIP_LEFT_RIGHT) #垂直翻转
y_img=img.transpose(Image.FLIP_TOP_BOTTOM) #水平翻转
new_imag=img.convert('L')
'''
模式
img.convert() 参数说明如下:
1 1位像素,黑和白,存成8位的像素
L 8位像素,黑白
P 8位像素,使用调色板映射到任何其他模式
RGB 3×8位像素,真彩
RGBA 4×8位像素,真彩+透明通道
CMYK 4×8位像素,颜色隔离
YCbCr 3×8位像素,彩色视频格式
I 32位整型像素
F 32位浮点型像素
'''
⑷ 如何用python绘制各种图形
1.环境
系统:windows10
python版本:python3.6.1
使用的库:matplotlib,numpy
2.numpy库产生随机数几种方法
import numpy as np
numpy.random
rand(d0,d1,...,dn)
In [2]: x=np.random.rand(2,5)
In [3]: x
Out[3]:
array([[ 0.84286554, 0.50007593, 0.66500549, 0.97387807, 0.03993009],
[ 0.46391661, 0.50717355, 0.21527461, 0.92692517, 0.2567891 ]])
randn(d0,d1,...,dn)查询结果为标准正态分布
In [4]: x=np.random.randn(2,5)
In [5]: x
Out[5]:
array([[-0.77195196, 0.26651203, -0.35045793, -0.0210377 , 0.89749635],
[-0.20229338, 1.44852833, -0.10858996, -1.65034606, -0.39793635]])
randint(low,high,size)
生成low到high之间(半开区间 [low, high)),size个数据
In [6]: x=np.random.randint(1,8,4)
In [7]: x
Out[7]: array([4, 4, 2, 7])
random_integers(low,high,size)
生成low到high之间(闭区间 [low, high)),size个数据
In [10]: x=np.random.random_integers(2,10,5)
In [11]: x
Out[11]: array([7, 4, 5, 4, 2])
3.散点图
x x轴
y y轴
s 圆点面积
c 颜色
marker 圆点形状
alpha 圆点透明度#其他图也类似这种配置
N=50# height=np.random.randint(150,180,20)# weight=np.random.randint(80,150,20)
x=np.random.randn(N)
y=np.random.randn(N)
plt.scatter(x,y,s=50,c='r',marker='o',alpha=0.5)
plt.show()
8.箱型图
import matplotlib.pyplot as pltimport numpy as npdata=np.random.normal(loc=0,scale=1,size=1000)#sym 点的形状,whis虚线的长度plt.boxplot(data,sym="o",whis=1.5)plt.show()
#sym 点的形状,whis虚线的长度
⑸ python 图像旋转怎么去除黑边
去除黑边现象的办法:
1)在做图像坐标映射反查的时候,算出当前点在原始图像的外部还是内部,若在外部,判断当前像素点的X或者Y位置,找临近四个边界的像
素值代替;
该方法太过繁琐,适合自己写程序实现,如若想调用现有的一些库函数,可以考虑2)做法:
2)将待旋转的图像进行边界填充,最不济的情况下可以扩充为原始图像的大小;
旋转边界填充图像;
计算原始图像经过旋转以后的结果图像的尺寸大小;
在边界填充旋转图像上截取目标图像;(图像都是按照图像中心旋转的);
附上一段matlab人脸根据人眼位置对齐的代码:
[plain] view plain
eye_angle = atan2( (eye_pts(2,2) - eye_pts(1,2)),(eye_pts(2,1) - eye_pts(1,1) ) ) * 180 / pi; % 人眼的倾斜角度
if eye_angle < 0
eye_angle = eye_angle + 360;
end
if floor(eye_angle) <= 5 || floor( 360 - eye_angle ) <= 5
continue;
end % 5度之内不做对齐操作
img = imread(img_path);
[m,n,~] = size(img);
img_pad = padarray(img,[m n],'both','replicate');% 扩充图像
img_pad_rotate = imrotate(img_pad,eye_angle,'bilinear'); % 旋转扩充图像
[m_pad_r,n_pad_r,~] = size(img_pad_rotate);
[plain] view plain
eye_angle = eye_angle * pi / 180;
f_cos = cos(eye_angle);f_sin = sin(eye_angle);
new_m = floor(m * abs(f_cos) + n * abs(f_sin));
new_n = floor(n * abs(f_sin) + m * abs(f_cos));% 最终对齐图像的大小
left = floor((n_pad_r - new_n) / 2);right = left + new_n;
bott = floor((m_pad_r - new_m) / 2);up = bott + new_m;
face_rorate = img_pad_rotate(bott : up,left : right,:); % 截取目标图像
figure,imshow(face_rorate)
⑹ J在windowes上对图片进行右键旋转后,在Python语言中对img 使用size()方法,获取的宽高仍为旋转之前的!
只有相应显示文字信息没变,但图片视觉效果和windows旋转的一样吗
⑺ 如何旋转一个多边形在python的Tkinter的画布
这个跟编码方式有关, 加上#-*- coding: utf8 -*- 就能显示中文啦 self.Button(self.trspt_frm, \ text='发送文件', \ command=self.send_file, \ ).pack(side=Tkinter.LEFT, fill=Tkinter.BOTH) 在pack里设置参数,就可以设置按钮的位置啦
⑻ 怎么样在python中让最后画出来的图翻转90度
importImage
importos
importglob
dir="f:mobile"
#取出指定文件
file=glob.glob(os.path.join(dir,'xxx.JPG'))
#打开图片
img=Image.open(file)
#显示图片
img.show()
printimg.format,img.size,img.mode
print"rotatingimage....."
im=img.rotate(90)
im.save(image)
我不知道你怎么画的,但旋转请参考以上代码
⑼ python能用鼠标旋转散点图吗
首先,你需要用到python的图形用户界面的模块 其次,你需要用到里面绘制界面和添加鼠标响应的功能模块
⑽ 用python做一个地球围绕太阳转的图形
平台: python2.7.10 + wxpython 3.0.2
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from __future__ import unicode_literals
import wx
__version__ = '0.1'
app_title = 'Temperature Translator - {}'.format(__version__)
class TempTranslator(wx.Frame):
def __init__(self, parent=None, size=(620, 200), title=app_title):
super(TempTranslator, self).__init__(parent, size=size, title=title)
self.SetMinSize(self.GetSize())
self.panel = wx.Panel(self)
self.init_layout()
self.panel.Layout()
self.Centre(wx.BOTH)
self.Show()
def init_layout(self):
font = self.GetFont()
font.SetWeight(wx.BOLD)
font.SetPointSize(15)
self.panel.SetFont(font)
vbox = wx.BoxSizer(wx.VERTICAL)
self.add_label(vbox, f2c=True)
self.f_tc1, self.c_tc1 = self.add_input(vbox, f2c=True)
self.f_tc1.Bind(wx.EVT_TEXT, self.on_f_text)
line = wx.StaticLine(self.panel, -1, style=wx.LI_HORIZONTAL)
style = wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP
vbox.Add(line, 0, style, 5)
self.add_label(vbox, f2c=False)
self.c_tc2, self.f_tc2 = self.add_input(vbox, f2c=False)
self.c_tc2.Bind(wx.EVT_TEXT, self.on_c_text)
self.panel.SetSizer(vbox)
def add_label(self, vbox, f2c=True):
if f2c:
text1 = 'Fahrenheit'
text2 = 'Celsius'
else:
text1 = 'Celsius'
text2 = 'Fahrenheit'
hbox = wx.BoxSizer(wx.HORIZONTAL)
label = wx.StaticText(self.panel, -1, text1, size=(-1, 30),
style=wx.ALIGN_CENTER)
hbox.Add(label, 1, wx.EXPAND, 10)
label = wx.StaticText(self.panel, -1, text2, size=(-1, 30),
style=wx.ALIGN_CENTER)
hbox.Add(label, 1, wx.EXPAND, 10)
vbox.Add(hbox, 0, wx.EXPAND, 10)
def add_input(self, vbox, f2c=True):
hbox = wx.BoxSizer(wx.HORIZONTAL)
tc1 = wx.TextCtrl(self.panel, -1, size=(260, 40), style=wx.TE_CENTER)
tc1.Bind(wx.EVT_TEXT, self.on_f_text)
label = wx.StaticText(self.panel, -1, ' = ')
tc2 = wx.TextCtrl(self.panel, -1, size=(260, 40), style=wx.TE_CENTER)
hbox.Add(tc1, 1, wx.EXPAND, 10)
hbox.Add(label, 0, wx.ALL | wx.EXPAND, 10)
hbox.Add(tc2, 1, wx.EXPAND, 10)
vbox.Add(hbox, 1, wx.EXPAND, 10)
return tc1, tc2
def on_f_text(self, evt):
f = self.f_tc1.GetValue()
self.c_tc1.SetValue('{}'.format(self.f2c(f)))
def on_c_text(self, evt):
c = self.c_tc2.GetValue()
self.f_tc2.SetValue('{}'.format(self.c2f(c)))
def f2c(self, f):
return (float(f) - 32) / 1.8 if f else ''
def c2f(self, c):
return float(c) * 1.8 + 32 if c else ''
if __name__ == '__main__':
app = wx.App()
TempTranslator()
app.MainLoop()