在Python中,是否有任何方法可以自動檢測PDF某個區域中的顏色,並將它們轉換爲RGB或將它們與圖例進行比較,然後獲取顏色?如何從PDF中檢測顏色Python
2
A
回答
1
根據您要從中提取信息的位置,您可以使用minecart
。它具有對顏色的強大支持,並且可以輕鬆轉換爲RGB。雖然你不能輸入的座標,並獲得顏色值在那裏,如果你想從一個形狀,你可以不喜歡以下獲得顏色信息:
import minecart
doc = minecart.Document(open("my-doc.pdf", "rb"))
page = doc.get_page(0)
BOX = (.5 * 72, # left bounding box edge
9 * 72, # bottom bounding box edge
1 * 72, # right bounding box edge
10 * 72) # top bounding box edge
for shape in page.shapes:
if shape.check_in_bbox(BOX):
r, g, b = shape.fill.color.as_rgb()
# do stuff with r, g, b
[免責聲明:我的作者minecart
]
1
Felipe的做法並沒有爲我工作,但我想出了這個:
#!/usr/bin/env python
# -*- Encoding: UTF-8 -*-
import minecart
colors = set()
with open("file.pdf", "rb") as file:
document = minecart.Document(file)
page = document.get_page(0)
for shape in page.shapes:
if shape.fill:
colors.add(shape.fill.color.as_rgb())
for color in colors: print color
這將打印在文檔的第一頁上的所有獨特的RGB值的整齊列表(你可以將它擴展到co。的所有頁面URSE)。
相關問題
- 1. Python中的RGB顏色檢測語言
- 2. Python中的主要顏色檢測
- 3. 如何檢測PDF是否包含pantone顏色?
- 4. 從物體中檢測顏色並更改其顏色ios
- 5. 使用Python的圖像顏色檢測
- 6. opencv中的顏色檢測
- 7. Java顏色檢測
- 8. Ghostscript顏色檢測
- 9. 檢測iDevice顏色
- 10. 硒 - 檢測顏色
- 11. Java顏色檢測
- 12. 如何檢測與顏色的碰撞?
- 13. 如何檢測OpenCV Python中的紅色?
- 14. 顏色從黑色和白色從PDF到IMG再次到PDF
- 15. Java:檢測顏色(例如,我的顏色是藍色的嗎?)
- 16. 顏色SURF檢測器
- 17. PHP顏色強度檢測
- 18. 碰撞檢測顏色
- 19. C#aforge顏色檢測
- 20. 顏色檢測算法
- 21. 檢測精靈的顏色
- 22. 顏色邊緣檢測+ opencv
- 23. 顏色檢測和分析
- 24. Opencv Android顏色檢測
- 25. 從pdf中識別rgb和cmyk顏色
- 26. 如何檢查顏色/從WINSPOOL API
- 27. 檢查顏色Opencv Python
- 28. Python圖像檢測PDF
- 29. 檢測如果顏色是在範圍
- 30. OpenCV顏色檢測爲黃色
也許你可以將PDF轉換成圖片格式(例如BMP)並分析它。 – WoJ