顯示具有 mac 標籤的文章。 顯示所有文章
顯示具有 mac 標籤的文章。 顯示所有文章

2024年10月20日 星期日

Ollama 基本指令

基本指令

  • 執行模型:Ollama 運行於本地環境,使用以下指令來啟動模型:
    ollama run <模型名稱>
    例如,若要運行 Llama2 模型:
    ollama run llama2
  • 管理模型:
    • 列出所有可用的模型:
      ollama list
    • 從模型庫中拉取新的模型:
      ollama pull <模型名稱>
    • 查看特定模型的詳細資訊:
      ollama show <模型名稱>
    • 刪除特定模型:
      ollama rm <模型名稱>

2024年10月13日 星期日

Combining Scanned Images into a PDF with OCR on Mac OS X

Combining Scanned Images into a PDF with OCR on Mac OS X

This guide will walk you through the process of combining multiple scanned images of book pages into a single PDF file on Mac OS X and using OCR (Optical Character Recognition) to convert the text into searchable, selectable electronic text.

1. Installing Required Tools

First, we need to install a few tools to handle image and PDF processing, as well as perform OCR. The following tools are required:

  • ImageMagick: For image format conversion and processing.
  • ocrmypdf: For performing OCR on PDF files.
  • Tesseract: OCR engine used for text recognition.
  • Poppler: A PDF utilities suite, which includes tools like pdfunite for merging PDFs.

Install these tools using Homebrew:

brew install imagemagick    # Install ImageMagick
brew install ocrmypdf       # Install OCRMyPDF
brew install tesseract-lang # Install Tesseract language packs
brew install poppler        # Install Poppler

2. Merging Images into a PDF

If your scanned output is in image format (e.g., JPG), you can use ImageMagick to combine multiple image files into a single PDF document. This ensures that the subsequent OCR process works on a single PDF file.

To combine all .jpg images in the current directory into a single 001.pdf file:

magick *.jpg 001.pdf

This command uses the magick tool from ImageMagick to merge all .jpg files in the directory into one PDF file named 001.pdf.

3. Running OCR on the PDF

Next, we use the ocrmypdf tool to perform OCR on the generated PDF file and save the output as a new file. In this step, we specify the OCR languages as English (eng) and Traditional Chinese (chi_tra).

Run the following command:

ocrmypdf -l eng+chi_tra+chi_tra_vert 001.pdf 001a.pdf

This command will apply OCR to the 001.pdf file and save the result as 001a.pdf. The -l eng+chi_tra+chi_tra_vert option indicates that both English and Traditional Chinese will be used for text recognition.

4. Merging Multiple OCR Processed PDFs

If you have multiple PDF files that need to be combined into a single final PDF, the pdfunite tool can do this easily. To merge the processed PDF files into a single output named combined_pdf.pdf, use the following command:

pdfunite 001a.pdf 002a.pdf 003a.pdf combined_pdf.pdf

This command merges 001a.pdf, 002a.pdf, and 003a.pdf into a single combined_pdf.pdf file.

Summary

By following these steps, you can:

  1. Merge scanned images into a PDF file.
  2. Use the Tesseract engine via ocrmypdf to perform OCR text recognition.
  3. Combine multiple PDF files into a final merged PDF.

This allows you to convert scanned images of book pages into a searchable, selectable, and copyable PDF document.

Mac OS X 環境下將圖片合併為PDF並進行OCR處理

將圖片合併為PDF並進行OCR處理

在這份說明文件中,我們將介紹如何在Mac OS X環境下,將多個掃描成圖片的書籍頁面合併為一個PDF檔案,並使用OCR(光學文字識別)將其中的文字轉換為可搜索和選取的電子文字。

1. 安裝必要的工具

首先,我們需要安裝一些工具來處理圖片和PDF,並進行OCR。以下是需要的工具:

  • ImageMagick:用於圖片格式轉換與處理。
  • ocrmypdf:用於將PDF檔案進行OCR處理。
  • Tesseract:OCR引擎,用於實際進行文字識別。
  • Poppler:PDF工具集,包含 pdfunite 等工具,用於合併PDF。

使用 Homebrew 安裝這些工具:

brew install imagemagick    # 安裝 ImageMagick
brew install ocrmypdf       # 安裝 OCRMyPDF
brew install tesseract-lang # 安裝 Tesseract 語言包
brew install poppler        # 安裝 Poppler

2. 圖片合併為PDF

當掃描結果以圖片格式(如 JPG)儲存時,我們可以使用 ImageMagick 將多個圖片檔案合併為單一 PDF 文件。這樣做可以保證後續的 OCR 處理僅在一個 PDF 檔案上進行。

將當前目錄下的所有 .jpg 圖片檔合併為 001.pdf:

magick *.jpg 001.pdf

這條指令將使用 ImageMagick 中的 magick 工具,將目錄中的所有 .jpg 檔案依序合併成一個 PDF 文件 001.pdf。

3. 執行 OCR 文字識別

接下來,我們使用 ocrmypdf 工具來對生成的 PDF 檔案進行 OCR 處理,並將處理後的 PDF 儲存為新的文件。在此步驟中,我們指定使用英語(eng)和繁體中文(chi_tra)作為 OCR 的語言。

執行指令:

ocrmypdf -l eng+chi_tra+chi_tra_vert 001.pdf 001a.pdf

這條指令會對 001.pdf 文件進行 OCR 文字識別,並將結果儲存為 001a.pdf。其中,-l eng+chi_tra+chi_tra_vert 表示同時使用英語和繁體中文進行文字識別。

4. 合併多個 OCR 處理後的 PDF 檔案

如果你有多個 PDF 檔案需要合併為一個最終的 PDF 檔案,pdfunite 工具可以輕鬆做到這點。將處理過的 PDF 檔案合併為單一檔案 combined_pdf.pdf:

pdfunite 001a.pdf 002a.pdf 003a.pdf combined_pdf.pdf

這條指令將 001a.pdf、002a.pdf 和 003a.pdf 三個檔案合併成一個 combined_pdf.pdf。

總結

透過這些步驟,你可以:

  1. 將掃描的圖片合併成 PDF 檔案。
  2. 使用 Tesseract 引擎透過 ocrmypdf 進行 OCR 文字識別。
  3. 將多個 PDF 檔案合併成一個完整的 PDF。

這樣,你就能將掃描成圖片的書籍內容轉換為可以搜索、選取和複製文字的 PDF 電子檔。

2024年10月6日 星期日

Mac OS X 下 Python套件matplotlib繪製中文標題散點圖表(Scatter Plot)


  • 匯入了必要的套件:seaborn、matplotlib.pyplot 和 matplotlib.font_manager。
  • 設定了字體和字號:使用 FontProperties 類別來指定字體檔案路徑和字號大小。
  • 載入了 tips 數據集:使用 sns.load_dataset 函數來載入 seaborn 的 tips 數據集。
  • 設定了 seaborn 的樣式:使用 sns.set() 函數來設定 seaborn 的預設樣式。
  • 畫了散點圖:使用 sns.scatterplot 函數來畫散點圖。
  • 設定了圖表標題:使用 plt.title 函數來設定圖表標題,並指定了中文字體和字號。
    import seaborn as sns
    import matplotlib.pyplot as plt
    import matplotlib.font_manager as fm
    
    # 設定字體和字號
    font = fm.FontProperties(fname='/Users/YOURNAME/Library/Fonts/jf-openhuninn-2.0.ttf', size=12)
    
    tips = sns.load_dataset("tips")
    sns.set()
    sns.scatterplot(x="total_bill", y="tip", data=tips)
    plt.title('餐廳小費關係圖', fontproperties=font)
    plt.show()
    
  • 2021年2月11日 星期四

    Apple M1 Mac 安裝 python3 程式庫

    python3 -m pip install --upgrade pip
    
    arch -x86_64 $(which python3) -m pip install numpy scipy matplotlib dbr
    

    2018年10月19日 星期五

    2015年10月18日 星期日

    Mac OS X El Capitan 10.11 + FT232 USB模組 + Arduino Pro mini (5V, 16MHz)

    材料

    • Arduino Pro mini x 1
    • FT232 USB 模組 x 1
    • USB傳輸線 x 1 (連結Mac電腦和 USB TO FT232)

    安裝Virtual COM Port Driver
    • 至FTDI網站找適合的驅動程式,範例安裝Mac OS X 10.9以上 x64 v2.3 FTDI USB Serial Driver
    FTDI網站下載VCP Driver

    接線
    • FT232 USB 模組和Arduino Pro mini 恰好六支pin腳對應上
      (DTR, RX<->TX, TX<-RX, VCC, CTS, BLK)

    DTR, RX<->TX, TX<->RX, VCC, CTS, BLK 分別對應好
    利用FT232 USB模組的pin腳和Arduino Pro mini連接
    接上電腦後應該就能看到LED亮燈


    上傳Arduino範例程式 : 範例 > 01.Basics > Blink
    • 板子:Arduino Pro Mini
    • 處理器:ATMega328 (5V, 16MHz)
    • 序列埠:找到您自己電腦上的,範例為 cu.usbserial-A9UHPBRJ
    • 燒錄器:AVRISP mkII


    板子選擇Arduino Pro mini

    處理器選擇 ATmega328 (5V, 16Mhz)

    序列埠選擇您自己電腦上對應的USB Serial Port

    燒錄器選擇AVRISP mkII

    按下選單左上方➡(上傳)功能鍵

    上傳時,正常情況應能看到 FT232 USB模組上的RX/TX LED一閃一滅,表示程式正傳輸到Arduino Pro mini 上。

    上傳成功後,接著您就能看到 Arduino Pro mini 上面的LED一閃一滅囉~ 恭喜啦!

    #


    2014年10月18日 星期六

    製作 Mac OS X Yosemite 開機安裝碟

    透過 App Store 直接升級至新版 Mac OS X Yosemite 或許是最快的方法。但對於需要更新多部 Mac 或打造一部 Hackintosh 而言,卻不一定是最理想的方式。

    如同以往的 Mac OS X 升級,完成更新安裝之後,installer安裝程式也會自動從應用程式(Applications)文件夾中消失。我們可透過同時按下鍵盤option鍵並用滑鼠點擊畫面上的Free Upgrade (免費升級)按鈕或是利用 Time Machine 備份檔案重新還原 installer安裝程式。為了節省時間,建議更新至新版 Yosemite 前最好還是製作一支 USB 開機安裝碟,方便日後使用。


    1. 下載 Yosemite Installer:打開 App Store,按下鍵盤 option 鍵,同時用滑鼠點擊畫面上的Free Upgrade (免費升級)按鈕,進行安裝程式下載。

    2. 檔案大小 5.16GB 需要一些時間進行下載


    3. 格式化USB隨身碟:準備一支至少8GB容量的USB隨身碟,先將裡面資料備份後,準備以「硬碟工具程式」進行隨身碟格式化。選擇磁碟格式:Mac OS 擴充格式(日誌式)、輸入名稱:Yosemite 後,進行磁碟機的清除工作。



    4. 寫入開機安裝碟:當Yosemite安裝檔案下載完成後,開啟「終端機」(Terminal)應用程式。並且直接貼上下列指令:

    5. sudo /Applications/Install\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia --volume /Volumes/Yosemite --applicationpath /Applications/Install\ OS\ X\ Yosemite.app --nointeraction
      

    6. 輸入密碼:依照畫面提示輸入帳號密碼,等待安裝檔案寫入USB隨身碟中,耐心稍待片刻,直到畫面上出現 Done. 提示。
    7. 看到畫面上出現 Done. 提示

    8. 以USB安裝碟開機:準備升級更新的 Mac 先插上 Yosemite 開機安裝碟,然後按住option鍵同時開機,直到安裝畫面出現後,依照步驟進行安裝即可。

    #

    2014年2月3日 星期一

    Mac OS X 10.9.1 + Wintec WBT-100 GPS Data Logger

    準備工作:完成藍芽配對與應用程式安裝

    完成 WBT-100 GPS 與 Mac OS X 藍芽配對

    至 gpsbabel.org 下載 GPSBabel-1.4.4.dmg 並完成安裝


    方法一:以GUI方式操作應用程式GPSBabelFE

    螢幕快照 2014-02-03 上午12.50.36.png

    選取 Device , 範例為 /dev/cu.WBT100-SPPslave

    螢幕快照 2014-02-03 上午12.50.52.png

    Download Format 為 Wintec WBT-100/200 GPS Download

    螢幕快照 2014-02-03 上午12.52.06.png

    設定Output Format為GPX XML, 範例 File Name 為 mytrack

    螢幕快照 2014-02-03 上午12.59.17.png 螢幕快照 2014-02-03 上午12.53.55.png

    按下Apply執行後,經過一小段時間,即可將GPS Data log 自WBT-100下載完成囉

    螢幕快照 2014-02-03 上午12.54.11.png

    以 Google Earth 開啟 mytrack

    螢幕快照 2014-02-03 上午1.03.10.png


    方法二:開終端機直接下指令

    /Applications/GPSBabelFE.app/Contents/MacOS/gpsbabel -i wbt -f/dev/cu.WBT100-SPPslave -o gpx -F ~/Desktop/mytrack.gpx
    

    2013年11月29日 星期五

    Mac OS X 安裝及使用  Homebrew

    ubuntu apt 用習慣的朋友,應該也能很快適應 Homebrew for Mac OS X的。

    安裝步驟參考官網及實際經驗筆記如下:
    > ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
    > brew update

    接著就能安裝自己想要的 UNIX Packages,如:wget, curl, lynx ...
    > brew install wget
    > brew install lynx

    查詢經安裝的套件列表 
    > brew list

    或是想要移除已經安裝的套件
    > brew uninstall wget

    自動更新已經安裝的套件
    > brew upgrade wget

    其他功能可以藉由Help看指令參數及用法 
    > brew help


    延伸閱讀: 

    #

    2013年10月27日 星期日

    Mac OS X USB裝置樹(裝置列表) : alias lsusb="system_profiler SPUSBDataType"

    Linux 環境下 lsusb 指令可以快速提供電腦上 USB 裝置的清單列表。

    Mac OS X 上雖無 lsusb 指令,但其實有對應的功能可以使用。

    點選 螢幕左上角的蘋果icon > 關於這台Mac > 更多資訊... > 系統報告 > USB

    就能顯示出目前系統的USB裝置樹。

    USB 裝置樹
    USB 裝置樹

    喜歡在終端機 (Terminal)手動下指令的話,可以執行 > system_profiler SPUSBDataType 指令。也能看到所有USB裝置列表。

    執行 system_profiler SPUSBDataType
    如果您真的執意想要執行 lsusb 指令的話,不妨就在 ~/.bash_profile  中利用alias指令將 system_profiler SPUSBDataType 指令 alias 成 lsusb 。


    alias lsusb="system_profiler SPUSBDataType"

    • 開啟編輯 ~/.bash_profile 設定檔加上上面 alias 指令存檔後。
    • 執行 > source ~/.bash_profile 。


    接著就能在終端機下文字指令 > lsusb 來看 USB 裝置清單囉。

    #




    2012年11月6日 星期二

    黑蘋果 Hackintosh Mac OS X Mountain Lion



    • Motherboard : Gigabyte Z77 D3H
    • CPU : Intel i7 3770
    • Memory : DDR3 1600 32GB Kingstone (8G*4) 
    • Video : MSI GTX650PE
    • SSD : Intel 330 120GB
    • OS : 購自 Apple App Store - Apple OS X Mountain Lion


    * 參考網址:http://www.metamuse.net/2012/09/2012-osx-1082-pc.html

    * Boot Loader : Chameleon-2.1-r2069
       參數: -v -x PCIRootUID=0

    * 驅動程式 Kexts : 懶人包


      1. run Kext Utilityy

    <install Network for GA-Z77-D3H motherboard>
      2. drag AtherosL1cEthernet.kext to Kext Utility window

    <install Audio for GA-Z77-D3H motherboard>
      3. run VoodooPatcher and wait...
      4. run VoodooLoader Installer and wait ...

    or

      3. drag VoodooHDA.kext to Kext Utility window
      4. drag appleHDADisabler.kext to Kext Utility window

    <install nVidia GTX 650 driver>
      5. download from AMD offical site

    #




    2012年2月9日 星期四

    台灣廠商是不是也在布局智慧電視 Smart TV?

    <blockquote>

    三星智慧電視銷量 今年衝2,500萬台

    • 2012-02-09 01:08 工商時報 【記者陳怡均/綜合外電報導】

         全球電視製造龍頭三星電子周三宣布,今年計畫銷售逾2,500萬台智慧電視(smart TV),期盼在蘋果等對手虎視眈眈的網路電視市場搶下一席之地。
         三星同時也計劃推出低價平面電視,以因應低階機種需求升溫。
         三星電子電視機事業主管金玄石(Kim Hyun-suk)表示,預期今年該公司在全球出貨5,000萬台平面電視,其中一半以上具備網路連結和互動電視功能。三星去年全球平面電視銷量約達4,300萬台。

    </blockquote>
    新聞來源:中時電子報

    Smart TV大概是繼HTPC(Home Theater Personal Computer)、STB(Set-Top Box)之後想要進入客廳的產品,少了一個額外的盒子,搭著換數位電視或是更大螢幕的電視換機潮,說實在的比較容易被一般家庭接受。畢竟也不是每個人都有時間每天下載一堆看不完的影片。想看影片就是希望能夠遙控器拿起來打開電視電源、選片馬上看。Smart TV搭配線上影城,這些就不再是困難的事情。

    目前可以看到有能力同時提供各種大小螢幕服務的設備廠商,大概就是蘋果 Apple (iPod / iPhone / iPad / Mac / Apple TV)、SONY和Samsung了。剩下Google大概也是循著Android的模式,開放其他設備廠商內建或以Google TV為基礎來搶市佔。

    而台灣廠商呢? 布局也許還沒浮出檯面? 不過現階段至少連搶市的聲量都還沒看見。

    延伸閱讀:智慧電視+Smart TV

    #







    2010年10月18日 星期一

    讓 Ubuntu 10 變成 Mac OS X

    來源:Macbuntu
    Ubuntu 10.10的執行效能算起來十分優異,現在更可以輕鬆就把Ubuntu的介面改為Mac OS X風格,而且還不影響原來的執行效能喔。

    至 SourceForge.net 下載最新版的 Macbuntu 10.10 v2.3。(直接下載 中央大學Mirror站)

    1. cd /tmp
    2. wget http://ncu.dl.sourceforge.net/project/macbuntu/macbuntu-10.10/v2.3/Macbuntu-10.10.tar.gz
    3. tar xzvf Macbuntu-10.10.tar.gz
    4. cd /tmp/Macbuntu-10.10
    5. ./install.sh

    接下來就依照畫面提示,完成安裝囉。只能說這實在太像了!