【【python3】将视频转换为代码视频】教程文章相关的互联网学习教程文章

python – PIL image.convert(“RGB”)是否将图像转换为sRGB或AdobeRGB?【代码】

我想使用Python中的PIL将图像从各种模式(如RGBa,CMYK等)批量转换为sRGB. 但是,我不确定,无论在哪里都找不到,image.convert("RGB") 功能将图像转换为sRGB或Adobe RGB.我的直觉说它转换为sRGB. 如果它转换为sRGB然后如果我传入Adobe RGB图像转换功能,它会成功转换为sRGB吗?解决方法:默认情况下,PIL与颜色空间无关(如sRGB和Adobe RGB). 您可能知道,RGB只是红色,绿色和蓝色的三个8位值. CMYK是四个8位值.当您使用Image.convert(‘RGB’...

Python:转换字符串以用于ctypes.c_void_p()【代码】

给一个字符串:msg="hello world"如何将其定义为ctypes.c_void_p()数据类型? 以下代码产生“无法转换为指针”异常:data=ctypes.c_void_p(msg)数据必须是C中的void *类型,因为它被传递给DLL. 我假设有一种方法可以使用struct包打包/解压缩字符串,但不幸的是我对这个过程非常不熟悉.解决方法:像这样的东西?使用ctypes.cast?>>> import ctypes >>> p1= ctypes.c_char_p("hi mom") >>> ctypes.cast( p1, ctypes.c_void_p ) c_void_...

python – NumPy将8位转换为16/32位图像【代码】

我正在使用OpenCV 2在YCbCr色彩空间中进行一些图像处理.目前我可以检测到由于转换RGB而产生的一些噪音 – > YCbCr然后YCbCr – > RGB,但如documentation所述:If you use cvtColor with 8-bit images, the conversion will have some information lost. For many applications, this will not be noticeable but it is recommended to use 32-bit images in applications that need the full range of colors or that convert an ...

python – 将2D Numpy灰度值数组转换为PIL图像【代码】

假设我在0到1的范围内有一个2D Numpy值数组,它代表一个灰度图像.然后我如何将其转换为PIL图像对象?迄今为止的所有尝试都产生了极其奇怪的散乱像素或黑色图像.for x in range(image.shape[0]):for y in range(image.shape[1]):image[y][x] = numpy.uint8(255 * (image[x][y] - min) / (max - min))#Create a PIL image. img = Image.fromarray(image, 'L')在上面的代码中,numpy数组图像通过(image [x] [y] – min)/(max – min...

将字符串’yyyy-mm-dd’转换为datetime python [复制]【代码】

参见英文答案 > Converting string into datetime 19个我有来自用户的原始输入,例如“2015-01-30”…对于我正在使用的查询,日期必须输入为字符串,如“yyyy-mm-dd”. 我希望在我的循环结束时将日期增加1个月.“2015-01-30”变为“2015-02-27”(理想情况下是下个月的最后一个工作日).我希望有人可以帮助我;我正在使用PYTHON,我想转换为datetime的原因是我找到了一个添加1个月的功能. 理想情况下,...

如何在python中将293.4662543之类的浮点数转换为293.47?【代码】

如何缩短我得到的浮动结果?点后面我只需要2位数.对不起,我真的不知道如何用英语更好地解释这个…… 谢谢解决方法:来自浮点指南的Python cheat sheet:"%.2f" % 1.2399 # returns "1.24" "%.3f" % 1.2399 # returns "1.240" "%.2f" % 1.2 # returns "1.20"使用round()是不对的,因为浮点数是binary fractions,不能准确表示十进制数字. 如果需要使用十进制数字进行计算,请在十进制模块中使用十进制类型.

python – 将csv.DictReader对象转换为字典列表?【代码】

一个csv文件names.csv有内容:first_name last_name Baked Beans Lovely Spam Wonderful Spam我想把它读成一个字典列表,第一行包含键:>>> import csv >>> with open('names.csv') as csvfile: ... reader = csv.DictReader(csvfile) ... for row in reader: ... print(row['first_name'], row['last_name']) ... Baked Beans Lovely Spam Wonderful Spam但是读者的类型是csv.DictReader吗?如何将阅读器转换为词典...

python – 将数据帧转换为元组列表【代码】

我有一个像这样的python pandas dataframe df:a b 1 3 3 6 5 7 6 4 7 8我想把它转移到一个列表:[(1,3),(3,6),(5,7),(6,4),(7,8)]谢谢.解决方法:如果性能很重要,请使用列表理解:[tuple(r) for r in df.values] # [(1, 3), (3, 6), (5, 7), (6, 4), (7, 8)]如果迭代列表而不是numpy数组,您可能会发现更好的性能:[tuple(r) for r in df.values.tolist()] # [(1, 3), (3, 6), (5, 7), (6, 4), (7, 8)]这个方法可以任意数量的...

使用Python / Numpy中的单词构建转换矩阵【代码】

我试图用这个数据构建一个33转换矩阵days=['rain', 'rain', 'rain', 'clouds', 'rain', 'sun', 'clouds', 'clouds', 'rain', 'sun', 'rain', 'rain', 'clouds', 'clouds', 'sun', 'sun', 'clouds', 'clouds', 'rain', 'clouds', 'sun', 'rain', 'rain', 'sun','sun', 'clouds', 'clouds', 'rain', 'rain', 'sun', 'sun', 'rain', 'rain', 'sun', 'clouds', 'clouds', 'sun', 'sun', 'clouds', 'rain', 'rain', 'rain', 'rain', 'su...

python – 如何将文件夹中的所有JPG文件转换为PDF并将它们组合起来?【代码】

我在一个文件夹(/ img /)中有一些19242972 JPG文件.我想1)将它们转换为PDF和2)将它们组合成一个PDF.但我没有成功.我是python的新手.请让我知道如何继续.from PIL import Image import glob from fpdf import FPDF # imagelist = [] for filename in glob.glob('img/*.jpg'): #assuming jpgim=Image.open(filename)imagelist.append(im)pdf = FPDF() # imagelist is the list with all image filenames for image in imagelist:pdf....

Python – 将Dataframe中的所有项目转换为字符串【代码】

我遵循以下过程:In Python, how do I convert all of the items in a list to floats?因为我的Dataframe的每一列都是列表,但我选择将所有值更改为字符串而不是浮点数. df = [str(i)for d in df] 但这失败了. 它只删除了除第一行列名之外的所有数据. 然后,在df.values中尝试df = [str(i)for i]导致将整个Dataframe更改为一个大的列表,但这会使数据过于混乱,无法满足我的脚本目标,即导出我的Oracle表的Dataframe. 有没有办法将我的D...

python – 将字符串的Pandas DataFrame转换为直方图【代码】

假设我有一个像这样创建的DataFrame:import pandas as pd s1 = pd.Series(['a', 'b', 'a', 'c', 'a', 'b']) s2 = pd.Series(['a', 'f', 'a', 'd', 'a', 'f', 'f']) d = pd.DataFrame({'s1': s1, 's2', s2})实际数据中的字符串中存在相当多的稀疏性.我想创建字符串出现的直方图,看起来像d.hist()(例如,带有子图)为s1和s2(每个子图一个)生成的字符串. 只是做d.hist()给出了这个错误:/Library/Python/2.7/site-packages/pandas/tool...

如何在python中将int转换为float?【代码】

有谁知道如何将int转换为float. 由于某种原因,它继续打印0.我希望它打印一个特定的小数.sum = 144 women_onboard = 314 proportion_womenclass3_survived = sum / np.size(women_onboard) print 'Proportion of women in class3 who survived is %s' % proportion_womenclass3_survived解决方法:除了John的答案之外,你还可以创建一个变量float,结果将产生float.>>> 144 / 314.0 0.4585987261146497

Python:二进制/十六进制字符串转换?【代码】

我有一个包含二进制和字符串字符的字符串,我想先将其转换为二进制,然后再转换为十六进制. 字符串如下:<81>^Q<81>"^Q^@^[)^G ^Q^A^S^A^V^@<83>^Cd<80><99>}^@N^@^@^A^@^@^@^@^@^@^@j如何在Python中转换此字符串,以便十六进制格式的输出类似于下面的内容?24208040901811001B12050809081223431235113245422F0A23000000000000000000001F解决方法:您可以像这样使用ord和hex:>>> s = 'some string' >>> hex_chars = map(hex,map(ord,s...

python – Pandas将Dataframe转换为嵌套的Json【代码】

我的问题基本上与这个问题相反: Create a Pandas DataFrame from deeply nested JSON 我想知道是否可以做相反的事情.给出如下表:Library Level School Major 2013 Total 200 MS_AVERY UGRAD GENERAL STUDIES GEST 5079 201 MS_AVERY UGRAD GENERAL STUDIES HIST 5 202 MS_AVERY UGRAD GENERAL STUDIES MELC 2 203 MS_AVERY UGRAD GENERAL STUDIES PHIL 10 204 ...

PYTHON3 - 相关标签