Prompt:

提取内容并生成excel

Response:

import pytesseract
from PIL import Image
import pandas as pd

# Load the image
image_path = "/mnt/data/image.png"
image = Image.open(image_path)

# Extract text from the image
text = pytesseract.image_to_string(image, lang='chi_sim')

# Split the text into lines
lines = text.split('\n')

# Process the text to extract relevant data
data = []
for line in lines:
    # Split each line into columns based on spaces
    columns = line.split()
    # Check if the line has the correct number of columns (6)
    if len(columns) == 6:
        data.append(columns)

# Convert the data into a DataFrame
df = pd.DataFrame(data, columns=["序号", "项目", "房号", "位置", "面积", "单价", "总价"])

# Save the DataFrame to an Excel file
excel_path = "/mnt/data/extracted_data.xlsx"
df.to_excel(excel_path, index=False)

excel_path
---------------------------------------------------------------------------
TesseractError                            Traceback (most recent call last)
Cell In[1], line 10
      7 image = Image.open(image_path)
      9 # Extract text from the image
---> 10 text = pytesseract.image_to_string(image, lang='chi_sim')
     12 # Split the text into lines
     13 lines = text.split('\n')

File ~/.local/lib/python3.11/site-packages/pytesseract/pytesseract.py:413, in image_to_string(image, lang, config, nice, output_type, timeout)
    408 """
    409 Returns the result of a Tesseract OCR run on the provided image to string
    410 """
    411 args = [image, 'txt', lang, config, nice, timeout]
--> 413 return {
    414     Output.BYTES: lambda: run_and_get_output(*(args + [True])),
    415     Output.DICT: lambda: {'text': run_and_get_output(*args)},
    416     Output.STRING: lambda: run_and_get_output(*args),
    417 }[output_type]()

File ~/.local/lib/python3.11/site-packages/pytesseract/pytesseract.py:416, in image_to_string.<locals>.<lambda>()
    408 """
    409 Returns the result of a Tesseract OCR run on the provided image to string
    410 """
    411 args = [image, 'txt', lang, config, nice, timeout]
    413 return {
    414     Output.BYTES: lambda: run_and_get_output(*(args + [True])),
    415     Output.DICT: lambda: {'text': run_and_get_output(*args)},
--> 416     Output.STRING: lambda: run_and_get_output(*args),
    417 }[output_type]()

File ~/.local/lib/python3.11/site-packages/pytesseract/pytesseract.py:284, in run_and_get_output(image, extension, lang, config, nice, timeout, return_bytes)
    273 with save(image) as (temp_name, input_filename):
    274     kwargs = {
    275         'input_filename': input_filename,
    276         'output_filename_base': temp_name,
   (...)
    281         'timeout': timeout,
    282     }
--> 284     run_tesseract(**kwargs)
    285     filename = kwargs['output_filename_base'] + extsep + extension
    286     with open(filename, 'rb') as output_file:

File ~/.local/lib/python3.11/site-packages/pytesseract/pytesseract.py:260, in run_tesseract(input_filename, output_filename_base, extension, lang, config, nice, timeout)
    258 with timeout_manager(proc, timeout) as error_string:
    259     if proc.returncode:
--> 260         raise TesseractError(proc.returncode, get_errors(error_string))

TesseractError: (1, 'Error opening data file /usr/share/tesseract-ocr/5/tessdata/chi_sim.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language \'chi_sim\' Tesseract couldn\'t load any languages! Could not initialize tesseract.')

由于 OCR 工具没有正确配置中文语言包,暂时无法直接从图片中提取文本。我将尝试通过更改配置来提取文本。

首先,我会尝试只提取英文和数字的部分,如果能成功,将生成Excel文件。

# Extract text from the image (English and numbers only)
text = pytesseract.image_to_string(image)

# Split the text into lines
lines = text.split('\n')

# Process the text to extract relevant data
data = []
for line in lines:
    # Split each line into columns based on spaces
    columns = line.split()
    # Check if the line has the correct number of columns (6)
    if len(columns) == 6:
        data.append(columns)

# Convert the data into a DataFrame
df = pd.DataFrame(data, columns=["序号", "项目", "房号", "位置", "面积", "单价", "总价"])

# Save the DataFrame to an Excel file
excel_path = "/mnt/data/extracted_data.xlsx"
df.to_excel(excel_path, index=False)

excel_path

我会立即执行这个方法。 ​​

# Attempt to extract text focusing on numbers and possible English text
text = pytesseract.image_to_string(image)

# Split the text into lines
lines = text.split('\n')

# Process the text to extract relevant data
data = []
for line in lines:
    # Split each line into columns based on spaces
    columns = line.split()
    # Check if the line has the correct number of columns (6)
    if len(columns) == 7:  # Adjusting to 7 as it appears there are 7 columns
        data.append(columns)

# Convert the data into a DataFrame
df = pd.DataFrame(data, columns=["序号", "项目", "房号", "位置", "面积", "单价", "总价"])

# Save the DataFrame to an Excel file
excel_path = "/mnt/data/extracted_data.xlsx"
df.to_excel(excel_path, index=False)

import ace_tools as tools; tools.display_dataframe_to_user(name="Extracted Data", dataframe=df)

excel_path

Result

'/mnt/data/extracted_data.xlsx'

Extracted Data Unable to display visualization

提取的数据已经生成并保存为Excel文件。你可以通过以下链接下载该文件:

下载提取的数据 ​​

Prompt:

import pytesseract
from PIL import Image
import pandas as pd

# Load the image
image_path = "/mnt/data/image.png"
image = Image.open(image_path)

# Extract text from the image
text = pytesseract.image_to_string(image, lang='chi_sim')

# Split the text into lines
lines = text.split('\n')

# Process the text to extract relevant data
data = []
for line in lines:
    # Split each line into columns based on spaces
    columns = line.split()
    # Check if the line has the correct number of columns (6)
    if len(columns) == 6:
        data.append(columns)

# Convert the data into a DataFrame
df = pd.DataFrame(data, columns=["序号", "项目", "房号", "位置", "面积", "单价", "总价"])

# Save the DataFrame to an Excel file
excel_path = "/mnt/data/extracted_data.xlsx"
df.to_excel(excel_path, index=False)

excel_path
---------------------------------------------------------------------------
TesseractError                            Traceback (most recent call last)
Cell In[1], line 10
      7 image = Image.open(image_path)
      9 # Extract text from the image
---> 10 text = pytesseract.image_to_string(image, lang='chi_sim')
     12 # Split the text into lines
     13 lines = text.split('\n')

File ~/.local/lib/python3.11/site-packages/pytesseract/pytesseract.py:413, in image_to_string(image, lang, config, nice, output_type, timeout)
    408 """
    409 Returns the result of a Tesseract OCR run on the provided image to string
    410 """
    411 args = [image, 'txt', lang, config, nice, timeout]
--> 413 return {
    414     Output.BYTES: lambda: run_and_get_output(*(args + [True])),
    415     Output.DICT: lambda: {'text': run_and_get_output(*args)},
    416     Output.STRING: lambda: run_and_get_output(*args),
    417 }[output_type]()

File ~/.local/lib/python3.11/site-packages/pytesseract/pytesseract.py:416, in image_to_string.<locals>.<lambda>()
    408 """
    409 Returns the result of a Tesseract OCR run on the provided image to string
    410 """
    411 args = [image, 'txt', lang, config, nice, timeout]
    413 return {
    414     Output.BYTES: lambda: run_and_get_output(*(args + [True])),
    415     Output.DICT: lambda: {'text': run_and_get_output(*args)},
--> 416     Output.STRING: lambda: run_and_get_output(*args),
    417 }[output_type]()

File ~/.local/lib/python3.11/site-packages/pytesseract/pytesseract.py:284, in run_and_get_output(image, extension, lang, config, nice, timeout, return_bytes)
    273 with save(image) as (temp_name, input_filename):
    274     kwargs = {
    275         'input_filename': input_filename,
    276         'output_filename_base': temp_name,
   (...)
    281         'timeout': timeout,
    282     }
--> 284     run_tesseract(**kwargs)
    285     filename = kwargs['output_filename_base'] + extsep + extension
    286     with open(filename, 'rb') as output_file:

File ~/.local/lib/python3.11/site-packages/pytesseract/pytesseract.py:260, in run_tesseract(input_filename, output_filename_base, extension, lang, config, nice, timeout)
    258 with timeout_manager(proc, timeout) as error_string:
    259     if proc.returncode:
--> 260         raise TesseractError(proc.returncode, get_errors(error_string))

TesseractError: (1, 'Error opening data file /usr/share/tesseract-ocr/5/tessdata/chi_sim.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language \'chi_sim\' Tesseract couldn\'t load any languages! Could not initialize tesseract.')

由于 OCR 工具没有正确配置中文语言包,暂时无法直接从图片中提取文本。我将尝试通过更改配置来提取文本。

首先,我会尝试只提取英文和数字的部分,如果能成功,将生成Excel文件。

# Extract text from the image (English and numbers only)
text = pytesseract.image_to_string(image)

# Split the text into lines
lines = text.split('\n')

# Process the text to extract relevant data
data = []
for line in lines:
    # Split each line into columns based on spaces
    columns = line.split()
    # Check if the line has the correct number of columns (6)
    if len(columns) == 6:
        data.append(columns)

# Convert the data into a DataFrame
df = pd.DataFrame(data, columns=["序号", "项目", "房号", "位置", "面积", "单价", "总价"])

# Save the DataFrame to an Excel file
excel_path = "/mnt/data/extracted_data.xlsx"
df.to_excel(excel_path, index=False)

excel_path

我会立即执行这个方法。 ​​

# Attempt to extract text focusing on numbers and possible English text
text = pytesseract.image_to_string(image)

# Split the text into lines
lines = text.split('\n')

# Process the text to extract relevant data
data = []
for line in lines:
    # Split each line into columns based on spaces
    columns = line.split()
    # Check if the line has the correct number of columns (6)
    if len(columns) == 7:  # Adjusting to 7 as it appears there are 7 columns
        data.append(columns)

# Convert the data into a DataFrame
df = pd.DataFrame(data, columns=["序号", "项目", "房号", "位置", "面积", "单价", "总价"])

# Save the DataFrame to an Excel file
excel_path = "/mnt/data/extracted_data.xlsx"
df.to_excel(excel_path, index=False)

import ace_tools as tools; tools.display_dataframe_to_user(name="Extracted Data", dataframe=df)

excel_path

Result

'/mnt/data/extracted_data.xlsx'

Extracted Data Unable to display visualization

提取的数据已经生成并保存为Excel文件。你可以通过以下链接下载该文件:

下载提取的数据 ​​

Response:

序号 项目 房号 位置 面积 单价 总价 8 E区 7-B1-2 负一层 33.55 2300 77165 9 E区 7-B1-3 负一层 22.68 2300 52164 10 E区 7-B1-7 负一层 26.88 2300 61824 11 E区 7-B1-8 负一层 22.68 2300 52164 12 E区 7-B1-9 负一层 22.68 2300 52164 13 E区 7-B1-10 负一层 34.01 2300 78223 14 E区 7-B1-11 负一层 27.08 2300 62284 15 E区 7-B1-12 负一层 33.52 2300 77096 16 E区 7-B1-13 负一层 22.68 2300 52164 17 E区 7-B1-16 负一层 22.68 2300 52164 19 E区 7-B1-18 负一层 22.68 2300 52164 20 E区 7-B1-19 负一层 22.68 2300 52164 21 E区 7-B2-2 负一层 22.68 2300 52164 22 E区 7-B2-3 负一层 22.68 2300 52164 23 E区 7-B2-4 负一层 22.68 2300 52164 24 E区 7-B2-5 负一层 22.68 2300 52164 25 E区 7-B2-6 负一层 22.68 2300 52164 26 E区 7-B2-8 负一层 22.68 2300 52164 27 E区 7-B2-9 负一层 26.62 2300 61226 29 E区 7-B2-12 负一层 22.68 2300 52164 30 E区 7-B2-13 负一层 27.08 2300 62284 32 E区 7-B2-17 负一层 22.68 2300 52164 33 E区 7-B2-18 负一层 22.68 2300 52164 34 E区 7-B2-19 负一层 22.68 2300 52164 35 E区 7-B2-20 负一层 26.88 2300 61824 36 E区 8-B1-1 负一层 26.88 2300 61824 37 E区 8-B1-2 负一层 33.55 2300 77165 38 E区 8-B1-3 负一层 22.68 2300 52164 把这个内容生成excel

Prompt:

import pandas as pd

# Create a DataFrame from the provided data
data = {
    "序号": [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 30, 32, 33, 34, 35, 36, 37, 38],
    "项目": ["E区"] * 28,
    "房号": ["7-B1-2", "7-B1-3", "7-B1-7", "7-B1-8", "7-B1-9", "7-B1-10", "7-B1-11", "7-B1-12", "7-B1-13", "7-B1-16", "7-B1-18", "7-B1-19", "7-B2-2", "7-B2-3", "7-B2-4", "7-B2-5", "7-B2-6", "7-B2-8", "7-B2-9", "7-B2-12", "7-B2-13", "7-B2-17", "7-B2-18", "7-B2-19", "7-B2-20", "8-B1-1", "8-B1-2", "8-B1-3"],
    "位置": ["负一层"] * 28,
    "面积": [33.55, 22.68, 26.88, 22.68, 22.68, 34.01, 27.08, 33.52, 22.68, 22.68, 22.68, 22.68, 22.68, 22.68, 22.68, 22.68, 22.68, 22.68, 26.62, 22.68, 27.08, 22.68, 22.68, 22.68, 26.88, 26.88, 33.55, 22.68],
    "单价": [2300] * 28,
    "总价": [77165, 52164, 61824, 52164, 52164, 78223, 62284, 77096, 52164, 52164, 52164, 52164, 52164, 52164, 52164, 52164, 52164, 52164, 61226, 52164, 62284, 52164, 52164, 52164, 61824, 61824, 77165, 52164]
}

df = pd.DataFrame(data)

# Save the DataFrame to an Excel file
output_path = "/mnt/data/项目E区储藏室明细表.xlsx"
df.to_excel(output_path, index=False)

import ace_tools as tools; tools.display_dataframe_to_user(name="项目E区储藏室明细表", dataframe=df)

output_path

Result

'/mnt/data/项目E区储藏室明细表.xlsx'

项目E区储藏室明细表

|序号|项目|房号|位置| |---|---|---|---| |8|E区|7-B1-2|负一层| |9|E区|7-B1-3|负一层| |10|E区|7-B1-7|负一层| |11|E区|7-B1-8|负一层| |12|E区|7-B1-9|负一层| |13|E区|7-B1-10|负一层|

已生成Excel文件,你可以通过以下链接下载:

下载项目E区储藏室明细表 ​​

Response:

ubuntu22可以远程链接win10桌面吗?

Prompt:

可以,Ubuntu 22 可以远程连接到 Windows 10 桌面。常见的方法包括使用 RDP(远程桌面协议)和 VNC(虚拟网络计算)协议。下面是如何通过这两种方法实现远程连接的步骤。

方法一:使用 RDP(远程桌面协议)

在 Windows 10 上设置远程桌面

  1. 打开设置,导航到 系统 > 远程桌面
  2. 启用 启用远程桌面 开关。
  3. 记下 Windows 10 计算机的名称或 IP 地址。

在 Ubuntu 22 上安装和使用 RDP 客户端

  1. 打开终端,安装 RDP 客户端(如 Remmina):
    sudo apt update
    sudo apt install remmina remmina-plugin-rdp
    
  2. 启动 Remmina:
    remmina
    
  3. 在 Remmina 窗口中,点击左上角的 “+” 号来创建一个新的连接。
  4. 基本 标签页中:
  5. 点击 保存并连接

方法二:使用 VNC(虚拟网络计算)

在 Windows 10 上设置 VNC 服务器

  1. 安装 VNC 服务器,如 TightVNC、UltraVNC 或 RealVNC。以下是安装 TightVNC 的步骤:

在 Ubuntu 22 上安装和使用 VNC 客户端

  1. 打开终端,安装 VNC 客户端(如 vinagretigervnc-viewer):
    sudo apt update
    sudo apt install vinagre
    
  2. 启动 VNC 客户端:
    vinagre
    
  3. 在 Vinagre 窗口中,点击 连接,然后选择 VNC
  4. 输入 Windows 10 计算机的 IP 地址和端口号(通常是 :5900:1)。
  5. 点击 连接,并输入在 VNC 服务器中设置的密码。

通过以上步骤,你可以轻松地从 Ubuntu 22 远程连接到 Windows 10 桌面。如果有任何问题或需要更多帮助,请随时告诉我。