对于量化项目,我需要经过颜色校正的图像,无论光照条件如何,都能一遍又一遍地产生相同的结果。
每个图像都包含一个 X-Rite 颜色检查器,其颜色以矩阵格式已知:
Reference=[[170, 189, 103],[46, 163, 224],[161, 133, 8],[52, 52, 52],[177, 128, 133],[64, 188, 157],[149, 86, 187],[85, 85, 85],[67, 108, 87],[108, 60, 94],[31, 199, 231],[121, 122, 122], [157, 122, 98],[99, 90, 193],[60, 54, 175],[160, 160, 160],[130, 150, 194],[166, 91, 80],[70, 148, 70],[200, 200, 200],[68, 82, 115],[44, 126, 214],[150, 61, 56],[242, 243, 243]]
Run Code Online (Sandbox Code Playgroud)
对于每张图像,我为作为示例的色卡计算相同的矩阵:
Actual_colors=[[114, 184, 137], [2, 151, 237], [118, 131, 55], [12, 25, 41], [111, 113, 177], [33, 178, 188], [88, 78, 227], [36, 64, 85], [30, …Run Code Online (Sandbox Code Playgroud) 我为图像构建了一个像素分类器,对于图像中的每个像素,我想定义它属于哪个预定义的颜色簇。它有效,但每张图像大约 5 分钟,我想我正在做一些肯定可以优化的非 Pythonic 的事情。
我们如何将函数直接映射到列表列表上?
#First I convert my image to a list
#Below list represents a true image size
list1=[[255, 114, 70],
[120, 89, 15],
[247, 190, 6],
[41, 38, 37],
[102, 102, 10],
[255,255,255]]*3583180
Run Code Online (Sandbox Code Playgroud)
然后我们定义了将颜色映射到的集群以及执行此操作的函数(取自PIL 库)
#Define colors of interest
#Colors of interest
RED=[255, 114, 70]
DARK_YELLOW=[120, 89, 15]
LIGHT_YELLOW=[247, 190, 6]
BLACK=[41, 38, 37]
GREY=[102, 102, 10]
WHITE=[255,255,255]
Colors=[RED, DARK_YELLOW, LIGHT_YELLOW, GREY, BLACK, WHITE]
#Function to find closes cluster by root and squareroot distance …Run Code Online (Sandbox Code Playgroud) import cloudscraper
import requests
scraper = cloudscraper.create_scraper() # returns a CloudScraper instance
# Or: scraper = cloudscraper.CloudScraper() # CloudScraper inherits from requests.Session
print (scraper.get("https://www.youtube.com/").text )
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-459-1f19dc044105> in <module>
2 import requests
3
----> 4 scraper = cloudscraper.create_scraper() # returns a CloudScraper instance
5 # Or: scraper = cloudscraper.CloudScraper() # CloudScraper inherits from requests.Session
6 print (scraper.get("https://www.youtube.com/").text )
~/.local/lib/python3.6/site-packages/cloudscraper/__init__.py in create_scraper(cls, sess, **kwargs)
315 Convenience function for creating a ready-to-go CloudScraper object.
316
--> …Run Code Online (Sandbox Code Playgroud) 我有一个列表列表,其中每个列表都包含一个字典和整数。有时会出现重复的列表,我希望直接从父列表中删除它们。目前,我正在创建一个新列表并迭代旧列表以确保仅附加唯一值,但我认为这是不好的做法。是否可以将其重写为具有列表理解的单行代码,或者可以直接过滤原始列表以提高性能?
TRIAL=[[{'http': '46.101.160.223:80', 'https': '46.101.160.223:80'}, 0],
[{'http': '66.70.178.214:9300', 'https': '66.70.178.214:9300'}, 0],
[{'http': '130.61.100.135:80', 'https': '130.61.100.135:80'}, 0],
[{'http': '157.245.27.9:3128', 'https': '157.245.27.9:3128'}, 0],
[{'http': '185.246.84.7:8080', 'https': '185.246.84.7:8080'}, 0],
[{'http': '185.246.84.7:8080', 'https': '185.246.84.7:8080'}, 0],
[{'http': '130.61.100.135:80', 'https': '130.61.100.135:80'}, 1]]
#We have some duplicates which we want to filter out if there with function
temporary_list=[]
for i in TRIAL:
if i[0] not in [item[0] for item in temporary_list]:
temporary_list.append(i)
temporary_list (desired outcome)
[[{'http': '46.101.160.223:80', 'https': '46.101.160.223:80'}, 0],
[{'http': '66.70.178.214:9300', 'https': '66.70.178.214:9300'}, 0],
[{'http': '130.61.100.135:80', …Run Code Online (Sandbox Code Playgroud) 我正在尝试合并多个具有许多列的 .xls 文件,但其中 1 列带有超链接。我尝试用 Python 来做到这一点,但总是遇到无法解决的错误。
为了简洁起见,超链接隐藏在文本部分下。以下按住 Ctrl 键单击的超链接是我在 .xls 文件中遇到的示例:ES2866911 (T3)。
为了提高再现性,我在下面添加了 .xls1 和 .xls2 示例。
xls1:
| 标题 | 出版物_编号 |
|---|---|
| P_A | ES2866911 (T3) |
| P_B | EP3887362 (A1) |
.xls2:
| 标题 | 出版物_编号 |
|---|---|
| 个人电脑 | AR118706 (A2) |
| P_D | ES2867600 (T3) |
期望的结果:
| 标题 | 出版物_编号 |
|---|---|
| P_A | ES2866911 (T3) |
| P_B | EP3887362 (A1) |
| 个人电脑 | AR118706 (A2) |
| P_D | ES2867600 (T3) |
我无法在不丢失格式或超链接的情况下将 .xls 文件导入 Python。此外,我无法将 .xls 文件转换为 .xlsx。我无法获取 .xlsx 格式的 .xls 文件。下面我简单总结一下我的尝试:
1.) 和 pandas 一起阅读是我的第一次尝试。很容易做到,但所有超链接都会在 PD 中丢失,而且原始文件的所有格式都会丢失。
2.) 使用 openpyxl.load 读取 .xls 文件
InvalidFileException: openpyxl does not …Run Code Online (Sandbox Code Playgroud) python ×5
list ×2
calibration ×1
colors ×1
dictionary ×1
excel ×1
for-loop ×1
numpy ×1
opencv ×1
openpyxl ×1
optimization ×1
pandas ×1
performance ×1
polynomials ×1
ssl ×1
sslcontext ×1
websocket ×1
xlsx ×1