Onenote
Microsoft Loop
Notion.so
Obsidian
Notable : import md file, export html,md,pdf
Joblin
Scrapbox.io
Onenote
Microsoft Loop
Notion.so
Obsidian
Notable : import md file, export html,md,pdf
Joblin
Scrapbox.io
เริ่มจากอ่านหนังสือเกี่ยวกับ pointcloud processing ถึงส่วนของ feature extraction แล้วเค้าพูดถึง Harris corner detector ใน image processing (pointcloud ใช้ Harris3d)
ก็เลยเสิร์จอ่านเรื่อง Harris corner detector ไปโผล่เว็บ opencv ไปเจอ sobel operator (คุ้นๆ) แล้วก็อ่านไปเรื่อยๆไปเจอคำว่า convolution คุ้นๆ แต่นึกไม่ออก อ่านไปอ่านมาก็อ้อ ใช้ใน CNN convolution neuron network ลืมไปได้ยังไง
ภาพบน convolution ของ image (discrete)
คือมี image f (มอง pixel x,y เป็น matrix ) กับ kernel/operator/filter y (matrix 3*3/5*5)
แล้วเราก็เอา kernel ไปวน convolution ทั่ว image เพื่อสร้าง image ใหม่
เช่น blur image ใช้ gaussian operator, edge image ใช้ sobel operator
ภาพล่าง convolution ของ signal (continuous) คือเปลี่ยนจาก ซิกม่าเป็นอินทิเกรต
แล้ว derivative มาจากไหน คือมันคุ้นๆว่า เวลาหา edge ของ image อะ มัน diff หาความเปลี่ยนแปลงของ pixel รอบๆ ถ้าค่า pixel ต่างกันมาก คือตรงนั้นมี edge
Sobel operator is a popular edge-detection filter that approximates the first derivative of the image. There are two Sobel kernels, one for detecting horizontal edges and one for vertical edges:
chatgpt
อ้อออ sobel operator คือเอามาใช้แทนการ diff ได้นี่เอง
แล้วก็ยังมี laplacian filter
the Laplacian filter approximates the second derivative and is used to detect areas of rapid intensity change (like edges).
chatgpt
คือไปอ่านเรื่องข้างบนนี้มา กับ กบก็พึ่งอ่านหนังสือ calculus จบไป เลยนึกขึ้นได้ว่าเรื่อง diff มันมีคำ 2 คำ ที่ความหมายคือการ diff นี่แหละ แต่ต่างกันยังไงไม่รู้
derivative (n/adj) represents the rate of change of a function at a particular point.
อัตราการเปลี่ยนแปลง ณ จุดๆนึง นี่เอง
differentiate (v) is the process of finding the derivative of a function.
ก็คือการคำนวณ diff
ปล. ย้อนไปที่ Harris corner detector ไปอ่านหลักการมัน (ซึ่งยังไม่เข้าใจ) มีพูดถึง Taylor expansion ก็ไปถามchatดู
the Harris corner detector uses a second-order Taylor expansion to model how the intensity of an image changes in the local neighborhood around each pixel
chatgpt
อ้อออ Harris corner detector ใช้ Taylor expansion ขั้นที่สองด้วยนะ ในการหาว่า pixel ณ จุดนั้นๆ มีความแตกต่างจาก pixel โดยรอบแค่ไหน (เพื่อเอาไประบุ corner จาก eigenvalues ของ Matrix M)
ไปต่อกันที่ Taylor expansion มันเอาไป ใช้ในการเขียนสมการ(ประมาณค่า) ของฟังก์ชันที่ซับซ้อน เช่น sin(x), e^x
ไม่ค่อยเข้าใจละ ไว้เจอกันรอบหน้าค่อยมาอ่านอีกรอบละกัน
คือว่า โปรแกรมpdf24เมื่อกี้มันพัง… พอinput pdfหลายๆไฟล์พร้อมกัน มันบอกว่าหา imageที่extractแล้วเก็บไว้ใน tmp folder ไม่เจอ .. ซึ่งปิดโปรแกรมเปิดใหม่ก็ไม่หาย เหมือนจะต้องรีเซ็ตคอม…
ก็เลย ถาม chatpgtให้มันเขียนโค๊ดให้หน่อย + แก้เองเยอะอยู่
ได้ความว่า
import fitz # pip install PyMuPDF
import os
import shutil
from pathlib import Path
def extract_images_from_pdf(pdf_path, save_folder):
doc = fitz.open(pdf_path)
print(pdf_path)
save_prefix = "_".join(element[:10] for element in pdf_path.split("\\"))
#save_prefix = pdf_path.replace("\\", "-")[0:20]
print(save_prefix)
img_index =0
for page_number in range(doc.page_count):
page = doc[page_number]
images = page.get_images(full=True)
#print("found images "+len(images))
for img_info in images:
img_index += 1
image_index = img_info[0]
#print(img_index,image_index)
base_image = doc.extract_image(image_index)
image_bytes = base_image["image"]
image_filename = f"{save_folder}/{save_prefix}_{img_index}.jpg"
with open(image_filename, "wb") as image_file:
image_file.write(image_bytes)
print("extracted images = "+str(img_index)+"\n")
doc.close()
def extract_images_from_pdfs(pdf_folder, save_folder):
files = [f for f in os.listdir(pdf_folder) if os.path.isfile(os.path.join(pdf_folder, f))]
for file in files:
#print(file)
if file.lower().endswith(('.pdf')):
filepath = os.path.join(pdf_folder, file)
extract_images_from_pdf(filepath, save_folder)
print("Done!")
extract_images_from_pdfs('Session 5 - Interfaces for the Body and Beyond','extracted_images')
คือใส่ชื่อ folder เป็น input แล้วอ่าน pdf ในโฟล์เดอร์นั้น extract image
ซึงอันนี้ ถ้ารูปต้นฉบับเป็น transparent มา มันจะใส่ background สีดำให้ ต่างกับตัวโปรแกรมpdf24 ที่เซฟเป็นสีขาวให้ ดูคลีนตากว่า
ละก็contrastสีเพี้ยนน ไม่รู้ว่ารูปต้นฉบับเป็นไฟล์อะไร
folder ismar นี่ล่มมาก ทั้งสีเพี้ยน ภาพมาเป็นเศษๆ ไม่รู้เป็นไร
กับอีกอย่างที่ยังทำไม่ได้คือ ถ้ารูปต้นฉบับ embed เป็น pdf มา (มักจะเป็นพวกกราฟที่อยากได้ …) ทั้งโปรแกรมpdf24 ทั้ง python lib ตัวนี้ยัง extract ออกมาให้ไม่ได้
พอดีจะหาไอเดียทำกราฟใส่เปเปอร์ ปกติก็จะนั่งเปิดอ่านทีละอัน นั่งcropอันที่ชอบละsaveเก็บไว้ในfolderบ้าง แปะใน powerpoint/excel บ้างแล้วแต่อารมณ์ เสร็จละก็มักจะหาไม่เจอว่ารูปนี้มาจากเปเปอร์ไหน….
ด้วยความขี้เกียจcropรูปละ เลยเซิร์จหาโปรแกรมละก็เจอ มีให้ดาวโหลดโปรแกรมลงคอมด้วยนะ
https://tools.pdf24.org/en/extract-images
คือลากไฟล์เยอะๆใส่ได้เลย ละมันจะextractรูปภาพออมาให้ ตอนที่เซฟยังแยกโฟลเดอร์ตามชื่อ paper อยู่ โชคดีที่ชื่อรูปยังมี prefix เป็นชื่อโฟลเดอร์อยู่ (ถ้าทำในเว็ป ชื่อรูปไม่มี prefix เป็น 0.png 1.png 2.png ไป)
เดี่ยวเขียน python ให้มันเอารูปออกมาจากโฟลเดอร์จะได้ดูง่ายๆ ถาม chatgpt กับเขียนเพิ่มเองอีกนิด
import os
import shutil
from pathlib import Path
def move_images_and_delete_folders(folder_path):
print("process on :"+folder_path)
# Get a list of all subdirectories
subdirectories = [f for f in os.listdir(folder_path) if os.path.isdir(os.path.join(folder_path, f))]
# Iterate through each subdirectory
for subdir in subdirectories:
print(subdir)
subdir_path = os.path.join(folder_path, subdir)
if not os.path.isdir(subdir_path):
print("not a directory, skip!")
continue
# Get a list of all files in the subdirectory
files = [f for f in os.listdir(subdir_path) if os.path.isfile(os.path.join(subdir_path, f))]
folder_contain_image = False
# Iterate through each file in the subdirectory
for file in files:
# Check if the file is an image (you can customize this check based on your file extensions)
if file.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
# Move the image file to the parent directory
source_file = os.path.join(subdir_path, file)
destination_file = os.path.join(folder_path, file)
shutil.move(source_file, destination_file)
folder_contain_image=True
# Delete the empty subdirectory
if(folder_contain_image):
os.rmdir(subdir_path)
# Replace 'your_folder_path' with the path to the folder containing subfolders
folder_path = os.getcwd()
move_images_and_delete_folders(folder_path)
説明変数คืออะไร เหมือนจะแปลออกแต่ก็งงๆ แล้วก็มันมีชื่อแถวๆนี้อยู่หลายตัว ตัวไหนเป็นตัวไหนไม่รู้ละ เลยมาเปิดเว็ปเช็คดู
ก็จะมี กลุ่มตัวแปร X ที่เป็น input
แต่แอบงง 予測変数 ตัวแปรทำนาย แปลมาแล้วชื่อเหมือนจะเป็น output
予測変数とは、結果変数 (目的変数や応答変数とも呼ばれます) を予測するために使用する入力変数です。
ตัวแปรทำนายคือ ตัวแปรinputที่ใช้ทำนายผลลัพธ์…โอเคตามนั้น
มันใช้ในการทำนาย ไม่ใช่ผลลัพธ์จากการทำนาย
ส่วนอีกกลุ่มคือ ตัวแปร Y ที่เป็น output/result มีดังนี้
เรามักจะเจอ Y กับ X เป็นคู่ๆตามนี้ (ทำไมเค้าเอา Y นำ X นะ…)
「目的変数&説明変数」
「従属変数&独立変数」
reference:
https://yoshida931.hatenablog.com/entry/2018/05/13/232801
https://best-biostatistics.com/correlation_regression/variables.html
pdftk : https://www.pdflabs.com/tools/pdftk-server/
gswin64 : https://ghostscript.com/releases/gsdnld.html
filenames = os.listdir()
result = ” “.join(filenames)
result
pdftk 1.pdf 2.pdf 3.pdf cat output merged.pdf
gswin64 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 –dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=merged_compress.pdf merged.pdf
pdf to png command
gswin64 -sDEVICE=pngalpha -sOutputFile=math.png -r144 math.pdf
เวลาที่ sudo apt-get install อะไรสักอย่างแล้วมันขึ้น
E: Unable to locate package xxx
ในเน็ตเค้าก็จะแนะนำให้ sudo apt-get update ก่อน
แต่มันก็ขึ้น W: Failed to fetch อีก
วิธีแก้ไขคือ ให้เราเคลียร์ข้างในโฟลเดอร์ /var/lib/apt/lists ซึ่งเก็บข้อมูลแพคเกจต่างๆไว้
โดยการ rename หรือ move มันไปไว้ที่อื่น sudo mv /var/lib/apt/lists ~/
**ไม่ควรลบทิ้ง เดี่ยวอะไรหายไปแล้วจะกู้คืนไม่ได้ วุ่นวายหนักกว่าเดิม
ลอง sudo apt-get update อีกรอบ น่าจะไม่มี warning/error ใดๆ
แต่ถ้ามันไม่ได้ ก็ลอง copy ไฟล์ /etc/apt/sources.list จากเครื่องที่ install package ได้มาใส่อีกเครื่องดู (จริงๆแค่เขียน repository เพิ่มเข้าไปข้างในไฟล์ก็ได้ แต่ก็ไม่รู้ว่าต้องเขียนอะไร)
#deb cdrom:[Ubuntu 20.04.3 LTS _Focal Fossa_ - Release amd64 (20210819)]/ focal main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://jp.archive.ubuntu.com/ubuntu/ focal main restricted
# deb-src http://jp.archive.ubuntu.com/ubuntu/ focal main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://jp.archive.ubuntu.com/ubuntu/ focal-updates main restricted
# deb-src http://jp.archive.ubuntu.com/ubuntu/ focal-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://jp.archive.ubuntu.com/ubuntu/ focal universe
# deb-src http://jp.archive.ubuntu.com/ubuntu/ focal universe
deb http://jp.archive.ubuntu.com/ubuntu/ focal-updates universe
# deb-src http://jp.archive.ubuntu.com/ubuntu/ focal-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://jp.archive.ubuntu.com/ubuntu/ focal multiverse
# deb-src http://jp.archive.ubuntu.com/ubuntu/ focal multiverse
deb http://jp.archive.ubuntu.com/ubuntu/ focal-updates multiverse
# deb-src http://jp.archive.ubuntu.com/ubuntu/ focal-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://jp.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
# deb-src http://jp.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu focal partner
# deb-src http://archive.canonical.com/ubuntu focal partner
deb http://security.ubuntu.com/ubuntu focal-security main restricted
# deb-src http://security.ubuntu.com/ubuntu focal-security main restricted
deb http://security.ubuntu.com/ubuntu focal-security universe
# deb-src http://security.ubuntu.com/ubuntu focal-security universe
deb http://security.ubuntu.com/ubuntu focal-security multiverse
# deb-src http://security.ubuntu.com/ubuntu focal-security multiverse
# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.
ใน ubuntu จะมีโปรแกรมชื่อ systemd เป็น service manager
ไฟล์ abc.service ต่างๆ จะอยู่ใน /etc/systemd/system เพื่อให้ service นั้นๆ run ตอนที่คอมเปิดเครื่อง/รีสตาร์ท
ไฟล์ .service ที่เราเขียนเอง จะถูกเก็บไว้เป็น symbolic link ของpathจริง ใน /etc/systemd/system
[Unit]
Description=remote shutdown service
[Service]
ExecStart=/bin/bash -c "python -m uvicorn shutdown_api:app --host 0.0.0.0 --port 7999 --reload"
Restart=always
Type=simple
WorkingDirectory=/mnt/shutdown_api/
RestartSec=10
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target
จริงๆแล้ว ใช้ ExecStart=/bin/bash -c “python3.8 /mnt/shutdown_api/shutdown_api.py” ก็น่าจะได้ แต่เซิฟเวอร์ที่ใช้อยู่เป็นอะไรไม่รู้รันคำสั่งธรรมดาไม่ได้ เลยต้องพิมพ์แบบยาวๆ
import uvicorn
from fastapi import FastAPI
import subprocess
app = FastAPI()
@app.get("/")
def shutdown():
#subprocess.run([f"shutdown -h now"], shell=True)
password = "serverpassword"
command = f"echo {password} | sudo -S shutdown -h now"
print(command)
subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=7999, reload=True)
ไฟล์ python นี้คือ ให้ uvicorn server รัน FastAPI application (app)
ส่วน app = FastAPI() ก็จะเรียก def shutdown() ถ้ามี HTTP GET command ถูกเรียกใข้งาน
จากการที่เรา พิมพ์ curl http://192.168.11.122:7999 ใน terminal
ปล. host=”0.0.0.0″ means that the server will listen on all available network interfaces on the host machine. This makes the server accessible from any IP address on the network.
วิธีติดตั้ง service
1. sudo systemctl daemon-reload
#to reload the systemd manager configuration
2. sudo systemctl enable shutdown.service
#to enable the service to start at boot (create symbolic link if not exist)
3. sudo systemctl start shutdown.service
#to start the service
4. sudo systemctl status shutdown.service
#to check the status of the service
ถ้า host=0.0.0.0 ตามที่เขียนไว้ใน python file คือ ok
แต่ถ้าเป็น host=127.0.0.1 คือเป็น loopback จะไม่สามารถเรียก http get จาก คอมเครื่องอื่นในเน็ตเวิคได้
5. netstat -an|more #to check all available services
ปล. เขียนแยกหลายๆ decorator ก็เหมือนจะได้นะ
@app.get(“/shutdown”)
async def shutdown():
@app.get(“/restart”)
async def restart():
ส่วน HTTP POST ดูใช้งานยากอยู่ ยังไม่เคยลอง แต่ประมาณนี้
@app.post(“/items/”)
async def create_item(item: Item):
curl --header "Content-Type: application/json" \
--request POST \
--data '{"name": "example item", "price": 9.99}' \
http://localhost:8000/items/
ตรง –data คือ ส่ง json structure เข้าไปเป็น input ที่ฟังก์ชัน
From: https://support.readyplayer.me/hc/en-us/articles/360020740897-How-do-I-use-a-GLB-model-in-Unity-