python中cap函数,pythoncmp函数

python 为什么lower方法和cap方法后面不能加()

map是一个高级函数,第一个参数为函数,第二个参数为可迭代对象(如列表,字符串等), 其作用就是把可迭代对象里的每个元素都应用到第一个函数中

创新互联公司2013年开创至今,是专业互联网技术服务公司,拥有项目成都网站建设、成都网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元二道江做网站,已为上家服务,为二道江各地企业和个人服务,联系电话:028-86922220

形象解释:

map(f, [x1, x2, ..., xn]) = [f(x1), f(x2), f(x3),..., f(xn)]

不加括号表示这个函数,加了括号就是在调用这个函数并返回值了

举个例子:

def f():

return 1

print(f)

print(f())

输出结果:

function f at 0x7fb59035f578

1

第一个打印的是函数及其内存地址,第二个打印的是调用函数f后返回的值(也就是1)

所以说不能加括号

Python画CAP曲线,计算AR值

听别人分享提到了CAP曲线,网上资料比较少,自己动手实践一发

输入: predictions , labels , cut_point

数据预览,左列labels,右列predictions

模型预测坏客户/企业的能力较好,和最优模型的接近程度为0.81

python怎么读取视屏文件的信息

用python读取视频有两种主要方法,大家可依据自己的需求进行使用。

方法一:

使用imageio库,没有安装的可用pip安装或自己下载。自己下载的话给大家推荐一个镜像网站:[pip镜像](mageio/%20python%E5%BA%93%E9%95%9C%E5%83%8F%E7%BD%91%E7%AB%99),安装好后重启终端即可调用。1234

import pylabimport imageio#视频的绝对路径filename = '/path/to/your/video.mp4'#可以选择解码工具vid = imageio.get_reader(filename, 'ffmpeg')for im in enumerate(vid): #image的类型是mageio.core.util.Image可用下面这一注释行转换为arrary

#image = skimage.img_as_float(im).astype(np.float32)

fig = pylab.figure()

fig.suptitle('image #{}'.format(num), fontsize=20)

pylab.imshow(image)

pylab.show()12345678910111213

方法二:

用cv2库,用这种方法的好处是返回的就是arrary,不用转换,但方法一可以指定显示某一帧,而这种方法是从头读到尾。

import numpy as npimport matplotlib.pyplot as pltimport pylabimport imageioimport skimage.ioimport numpy as np

import cv2

cap = cv2.VideoCapture('/path/to/your/video.mp4')

while(cap.isOpened()):

ret, frame = cap.read()

cv2.imshow('image', frame)

k = cv2.waitKey(20)

#q键退出

if (k 0xff == ord('q')):

break cap.release()

cv2.destroyAllWindows()1234567891011121314151617181920

大家可能注意到,两种方法的显示方法也是不一样的,这里不详细展开,实践一下便很清楚了。

Python练习 将list中的字符串依次转为首字母大写(不使用title)

def cap_upper(lista):

for i in xrange(len(lista)):

lista[i]=lista[i][0].upper()+lista[i][1:]

return lista

aaa=['dog','cat']

print cap_upper(aaa)

不过我记得有个首字母大写函数capitalize(),直接循环调用这函数就行

python如何能采集多个摄像头的数据

可以,用PYQT+CV2,四个USB连接成功,程序如下,UI要自己搞了,放不下

# -*- coding: utf-8 -*-

import sys#, time

from PyQt5 import QtWidgets

from PyQt5.QtCore import QTimer, QThread, pyqtSignal

from Ui_cv2ui_thread import Ui_MainWindow

import cv2 as cv

from PyQt5.QtGui import QImage, QPixmap

from PyQt5.QtWidgets import (QApplication, QDialog, QFileDialog, QGridLayout,

QLabel, QPushButton, QColorDialog)

import numpy as np

class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):

def __init__(self, parent=None):

super(MainWindow, self).__init__(parent=parent)

self.setupUi(self) #这个一定要在这个最前面位置

# define the slot for pushbutton to save the merged image

self.pushButton.clicked.connect(self.savemergeimage)

self.img = np.ndarray(()) #空的numpy array

self.img1 = np.ndarray(())

self.img2= np.ndarray(())

self.img3= np.ndarray(())

self.img4= np.ndarray(())

self.img4= np.empty([960,1280, 3], int)

self.cap = cv.VideoCapture(3) #注意,由大开到小,很重要

self.cap.set(3, 640) # setup the resolution of CCD

self.cap.set(4, 480)

ret, self.img=self.cap.read()

self.cap1 = cv.VideoCapture(2)

self.cap1.set(3, 640)

self.cap1.set(4, 480)

ret, self.img1=self.cap1.read()

self.cap2 = cv.VideoCapture(1)

self.cap2.set(3, 640)

self.cap2.set(4, 480)

ret, self.img2=self.cap2.read()

self.cap3 = cv.VideoCapture(0)

self.cap3.set(3, 640)

self.cap3.set(4, 480)

ret, self.img3=self.cap3.read()

#time.sleep(1)也许需要延迟,等他准备好

# 初始化一个定时器,在其他条件下用的

#self.timer = QTimer(self)

# 实例化一个线程

self.work0= WorkThread()

self.work0.trigger.connect(self.ccd2)

# 定义时间任务是一次性任务就设定下一行

#self.timer.setSingleShot(True)

# 启动时间任务,注意一致性

self.work0.start()

# 实例化一个线程

self.work= WorkThread()

# 多线程的信号触发连接到ccd3

self.work.trigger.connect(self.ccd3)

self.work.start()

# 实例化一个线程

self.work2 = WorkThread()

# 多线程的信号触发连接到ccd4

self.work2.trigger.connect(self.ccd4)

self.work2.start()

# 实例化一个线程

self.work3 = WorkThread()

# 多线程的信号触发连接到ccd1

self.work3.trigger.connect(self.ccdmerge)

self.work3.start()

self.work4 = WorkThread()

# 多线程的信号触发连接到ccd1

self.work4.trigger.connect(self.ccd1)

self.work4.start()

def refreshShowa(self):#显示ccd1到label1

# 提取图像的尺寸和通道, 用于将opencv下的image转换成Qimage

height, width, channel = self.img.shape

bytesPerLine = 3 * width

self.qImg = QImage(self.img.data, width, height, bytesPerLine,

QImage.Format_RGB888).rgbSwapped()

# 将Qimage显示出来

self.label.setPixmap(QPixmap.fromImage(self.qImg))

def refreshShowb(self):#显示ccd2到label2

# 提取图像的尺寸和通道, 用于将opencv下的image转换成Qimage

height, width, channel = self.img1.shape

bytesPerLine = 3 * width

self.qImg1 = QImage(self.img1.data, width, height, bytesPerLine,

QImage.Format_RGB888).rgbSwapped()

# 将Qimage显示出来

self.label_2.setPixmap(QPixmap.fromImage( self.qImg1))

def refreshShowc(self):#显示ccd3到label3

# 提取图像的尺寸和通道, 用于将opencv下的image转换成Qimage

height, width, channel = self.img2.shape

bytesPerLine = 3 * width

self.qImg2 = QImage(self.img2.data, width, height, bytesPerLine,

QImage.Format_RGB888).rgbSwapped()

# 将Qimage显示出来

self.label_3.setPixmap(QPixmap.fromImage( self.qImg2))

def refreshShowd(self):#显示ccd4到label4

# 提取图像的尺寸和通道, 用于将opencv下的image转换成Qimage

height, width, channel = self.img3.shape

bytesPerLine = 3 * width

self.qImg3 = QImage(self.img3.data, width, height, bytesPerLine,

QImage.Format_RGB888).rgbSwapped()

# 将Qimage显示出来

self.label_4.setPixmap(QPixmap.fromImage( self.qImg3))

def refreshShowe(self):#显示合并的影像到label6

# 提取图像的尺寸和通道, 用于将opencv下的image转换成Qimage

height, width, channel = self.img4.shape

bytesPerLine = 3 * width

self.qImg4 = QImage(self.img4.data, width, height, bytesPerLine,

QImage.Format_RGB888).rgbSwapped()

# 将Qimage显示出来

self.label_6.setPixmap(QPixmap.fromImage( self.qImg4))

def ccd1(self):

self.cap.set(3, 640)

self.cap.set(4, 480)

ret, self.img = self.cap.read()

self.refreshShowa()

# 启动另一个线程

self.work0.start()#注意一致性

def ccd2(self, str):

self.cap1.set(3, 640)

self.cap1.set(4, 480)

ret, self.img1 = self.cap1.read()

self.refreshShowb()

self.work.start()#注意一致性

def ccd3(self, str):

self.cap2.set(3, 640)

self.cap2.set(4, 480)

ret, self.img2= self.cap2.read()

self.refreshShowc()

self.work2.start()#注意一致性

def ccd4(self, str):

self.cap3.set(3, 640)

self.cap3.set(4, 480)

ret, self.img3 = self.cap3.read()

self.refreshShowd()

self.work3.start()#注意一致性

def ccdmerge(self, str):

self.img4=np.hstack((self.img, self.img1))

self.img4=np.vstack((self.img4, np.hstack((self.img2, self.img3))))

#print ('here is a merge process') 可以用来判断多线程的执行

self.refreshShowe() #later to remove the remark

self.work4.start()#注意一致性

def savemergeimage(self):

# 调用存储文件dialog

fileName, tmp = QFileDialog.getSaveFileName(

self, 'Save Image', './__data', '*.png *.jpg *.bmp', '*.png')

if fileName == '':

return

if self.img.size == 1:

return

# 调用opencv写入图像

cv.imwrite(fileName,self.img4)

class WorkThread(QThread): #多线程核心,非常重要

# 定义一个信号

trigger = pyqtSignal(str)

def __int__(self):

# 初始化函数,默认

super(WorkThread, self).__init__()

def run(self):

self.trigger.emit('')

if __name__ == "__main__":

app = QtWidgets.QApplication(sys.argv)

w = MainWindow()

w.show()

sys.exit(app.exec_())

python皮卡丘编程代码

import turtle

def getPosition(x, y):

turtle.setx(x)

turtle.sety(y)

print(x, y)

class Pikachu:

def __init__(self):

self.t = turtle.Turtle()

t = self.t

t.pensize(3)

t.speed(9)

t.ondrag(getPosition)

def noTrace_goto(self, x, y):

self.t.penup()

self.t.goto(x, y)

self.t.pendown()

def leftEye(self, x, y):

self.noTrace_goto(x, y)

t = self.t

t.seth(0)

t.fillcolor('#333333')

t.begin_fill()

t.circle(22)

t.end_fill()

self.noTrace_goto(x, y+10)

t.fillcolor('#000000')

t.begin_fill()

t.circle(10)

t.end_fill()

self.noTrace_goto(x+6, y + 22)

t.fillcolor('#ffffff')

t.begin_fill()

t.circle(10)

t.end_fill()

def rightEye(self, x, y):

self.noTrace_goto(x, y)

t = self.t

t.seth(0)

t.fillcolor('#333333')

t.begin_fill()

t.circle(22)

t.end_fill()

self.noTrace_goto(x, y+10)

t.fillcolor('#000000')

t.begin_fill()

t.circle(10)

t.end_fill()

self.noTrace_goto(x-6, y + 22)

t.fillcolor('#ffffff')

t.begin_fill()

t.circle(10)

t.end_fill()

def mouth(self, x, y):

self.noTrace_goto(x, y)

t = self.t

t.fillcolor('#88141D')

t.begin_fill()

# 下嘴唇

l1 = []

l2 = []

t.seth(190)

a = 0.7

for i in range(28):

a += 0.1

t.right(3)

t.fd(a)

l1.append(t.position())

self.noTrace_goto(x, y)

t.seth(10)

a = 0.7

for i in range(28):

a += 0.1

t.left(3)

t.fd(a)

l2.append(t.position())

# 上嘴唇

t.seth(10)

t.circle(50, 15)

t.left(180)

t.circle(-50, 15)

t.circle(-50, 40)

t.seth(233)

t.circle(-50, 55)

t.left(180)

t.circle(50, 12.1)

t.end_fill()

# 舌头

self.noTrace_goto(17, 54)

t.fillcolor('#DD716F')

t.begin_fill()

t.seth(145)

t.circle(40, 86)

t.penup()

for pos in reversed(l1[:20]):

t.goto(pos[0], pos[1]+1.5)

for pos in l2[:20]:

t.goto(pos[0], pos[1]+1.5)

t.pendown()

t.end_fill()

# 鼻子

self.noTrace_goto(-17, 94)

t.seth(8)

t.fd(4)

t.back(8)

# 红脸颊

def leftCheek(self, x, y):

turtle.tracer(False)

t = self.t

self.noTrace_goto(x, y)

t.seth(300)

t.fillcolor('#DD4D28')

t.begin_fill()

a = 2.3

for i in range(120):

if 0 = i 30 or 60 = i 90:

a -= 0.05

t.lt(3)

t.fd(a)

else:

a += 0.05

t.lt(3)

t.fd(a)

t.end_fill()

turtle.tracer(True)

def rightCheek(self, x, y):

t = self.t

turtle.tracer(False)

self.noTrace_goto(x, y)

t.seth(60)

t.fillcolor('#DD4D28')

t.begin_fill()

a = 2.3

for i in range(120):

if 0 = i 30 or 60 = i 90:

a -= 0.05

t.lt(3)

t.fd(a)

else:

a += 0.05

t.lt(3)

t.fd(a)

t.end_fill()

turtle.tracer(True)

def colorLeftEar(self, x, y):

t = self.t

self.noTrace_goto(x, y)

t.fillcolor('#000000')

t.begin_fill()

t.seth(330)

t.circle(100, 35)

t.seth(219)

t.circle(-300, 19)

t.seth(110)

t.circle(-30, 50)

t.circle(-300, 10)

t.end_fill()

def colorRightEar(self, x, y):

t = self.t

self.noTrace_goto(x, y)

t.fillcolor('#000000')

t.begin_fill()

t.seth(300)

t.circle(-100, 30)

t.seth(35)

t.circle(300, 15)

t.circle(30, 50)

t.seth(190)

t.circle(300, 17)

t.end_fill()

def body(self):

t = self.t

t.fillcolor('#F6D02F')

t.begin_fill()

# 右脸轮廓

t.penup()

t.circle(130, 40)

t.pendown()

t.circle(100, 105)

t.left(180)

t.circle(-100, 5)

# 右耳朵

t.seth(20)

t.circle(300, 30)

t.circle(30, 50)

t.seth(190)

t.circle(300, 36)

# 上轮廓

t.seth(150)

t.circle(150, 70)

# 左耳朵

t.seth(200)

t.circle(300, 40)

t.circle(30, 50)

t.seth(20)

t.circle(300, 35)

#print(t.pos())

# 左脸轮廓

t.seth(240)

t.circle(105, 95)

t.left(180)

t.circle(-105, 5)

# 左手

t.seth(210)

t.circle(500, 18)

t.seth(200)

t.fd(10)

t.seth(280)

t.fd(7)

t.seth(210)

t.fd(10)

t.seth(300)

t.circle(10, 80)

t.seth(220)

t.fd(10)

t.seth(300)

t.circle(10, 80)

t.seth(240)

t.fd(12)

t.seth(0)

t.fd(13)

t.seth(240)

t.circle(10, 70)

t.seth(10)

t.circle(10, 70)

t.seth(10)

t.circle(300, 18)

t.seth(75)

t.circle(500, 8)

t.left(180)

t.circle(-500, 15)

t.seth(250)

t.circle(100, 65)

# 左脚

t.seth(320)

t.circle(100, 5)

t.left(180)

t.circle(-100, 5)

t.seth(220)

t.circle(200, 20)

t.circle(20, 70)

t.seth(60)

t.circle(-100, 20)

t.left(180)

t.circle(100, 20)

t.seth(300)

t.circle(10, 70)

t.seth(60)

t.circle(-100, 20)

t.left(180)

t.circle(100, 20)

t.seth(10)

t.circle(100, 60)

# 横向

t.seth(180)

t.circle(-100, 10)

t.left(180)

t.circle(100, 10)

t.seth(5)

t.circle(100, 10)

t.circle(-100, 40)

t.circle(100, 35)

t.left(180)

t.circle(-100, 10)

# 右脚

t.seth(290)

t.circle(100, 55)

t.circle(10, 50)

t.seth(120)

t.circle(100, 20)

t.left(180)

t.circle(-100, 20)

t.seth(0)

t.circle(10, 50)

t.seth(110)

t.circle(100, 20)

t.left(180)

t.circle(-100, 20)

t.seth(30)

t.circle(20, 50)

t.seth(100)

t.circle(100, 40)

# 右侧身体轮廓

t.seth(200)

t.circle(-100, 5)

t.left(180)

t.circle(100, 5)

t.left(30)

t.circle(100, 75)

t.right(15)

t.circle(-300, 21)

t.left(180)

t.circle(300, 3)

# 右手

t.seth(43)

t.circle(200, 60)

t.right(10)

t.fd(10)

t.circle(5, 160)

t.seth(90)

t.circle(5, 160)

t.seth(90)

t.fd(10)

t.seth(90)

t.circle(5, 180)

t.fd(10)

t.left(180)

t.left(20)

t.fd(10)

t.circle(5, 170)

t.fd(10)

t.seth(240)

t.circle(50, 30)

t.end_fill()

self.noTrace_goto(130, 125)

t.seth(-20)

t.fd(5)

t.circle(-5, 160)

t.fd(5)

# 手指纹

self.noTrace_goto(166, 130)

t.seth(-90)

t.fd(3)

t.circle(-4, 180)

t.fd(3)

t.seth(-90)

t.fd(3)

t.circle(-4, 180)

t.fd(3)

# 尾巴

self.noTrace_goto(168, 134)

t.fillcolor('#F6D02F')

t.begin_fill()

t.seth(40)

t.fd(200)

t.seth(-80)

t.fd(150)

t.seth(210)

t.fd(150)

t.left(90)

t.fd(100)

t.right(95)

t.fd(100)

t.left(110)

t.fd(70)

t.right(110)

t.fd(80)

t.left(110)

t.fd(30)

t.right(110)

t.fd(32)

t.right(106)

t.circle(100, 25)

t.right(15)

t.circle(-300, 2)

##############

#print(t.pos())

t.seth(30)

t.fd(40)

t.left(100)

t.fd(70)

t.right(100)

t.fd(80)

t.left(100)

t.fd(46)

t.seth(66)

t.circle(200, 38)

t.right(10)

t.fd(10)

t.end_fill()

# 尾巴花纹

t.fillcolor('#923E24')

self.noTrace_goto(126.82, -156.84)

t.begin_fill()

t.seth(30)

t.fd(40)

t.left(100)

t.fd(40)

t.pencolor('#923e24')

t.seth(-30)

t.fd(30)

t.left(140)

t.fd(20)

t.right(150)

t.fd(20)

t.left(150)

t.fd(20)

t.right(150)

t.fd(20)

t.left(130)

t.fd(18)

t.pencolor('#000000')

t.seth(-45)

t.fd(67)

t.right(110)

t.fd(80)

t.left(110)

t.fd(30)

t.right(110)

t.fd(32)

t.right(106)

t.circle(100, 25)

t.right(15)

t.circle(-300, 2)

t.end_fill()

# 帽子、眼睛、嘴巴、脸颊

self.cap(-134.07, 147.81)

self.mouth(-5, 25)

self.leftCheek(-126, 32)

self.rightCheek(107, 63)

self.colorLeftEar(-250, 100)

self.colorRightEar(140, 270)

self.leftEye(-85, 90)

self.rightEye(50, 110)

t.hideturtle()

def cap(self, x, y):

self.noTrace_goto(x, y)

t = self.t

t.fillcolor('#CD0000')

t.begin_fill()

t.seth(200)

t.circle(400, 7)

t.left(180)

t.circle(-400, 30)

t.circle(30, 60)

t.fd(50)

t.circle(30, 45)

t.fd(60)

t.left(5)

t.circle(30, 70)

t.right(20)

t.circle(200, 70)

t.circle(30, 60)

t.fd(70)

# print(t.pos())

t.right(35)

t.fd(50)

t.circle(8, 100)

t.end_fill()

self.noTrace_goto(-168.47, 185.52)

t.seth(36)

t.circle(-270, 54)

t.left(180)

t.circle(270, 27)

t.circle(-80, 98)

t.fillcolor('#444444')

t.begin_fill()

t.left(180)

t.circle(80, 197)

t.left(58)

t.circle(200, 45)

t.end_fill()

self.noTrace_goto(-58, 270)

t.pencolor('#228B22')

t.dot(35)

self.noTrace_goto(-30, 280)

t.fillcolor('#228B22')

t.begin_fill()

t.seth(100)

t.circle(30, 180)

t.seth(190)

t.fd(15)

t.seth(100)

t.circle(-45, 180)

t.right(90)

t.fd(15)

t.end_fill()

t.pencolor('#000000')

def start(self):

self.body()

def main():

print('Painting the Pikachu... ')

turtle.screensize(800, 600)

turtle.title('Pikachu')

pikachu = Pikachu()

pikachu.start()

turtle.mainloop()

if __name__ == '__main__':

main()

标题名称:python中cap函数,pythoncmp函数
标题链接:https://www.cdcxhl.com/article34/phpcse.html

成都网站建设公司_创新互联,为您提供商城网站移动网站建设云服务器定制开发网站营销网站设计公司

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

h5响应式网站建设