創作內容

0 GP

listdir Hu moments

作者:Jarvis│2021-05-27 16:17:57│巴幣:0│人氣:155
#計算資料夾內圖片的Hu moments
#路徑格式需特別留意
from math import copysign, log10
import cv2
import os
import numpy as np
 
def main():
    showLogTransformedHuMoments = True
    filename ='C:/Users/Jarvis/Desktop/523/Selected_front/'
    allFileList = os.listdir(filename)
    for file in allFileList:
        im = cv2.imread('C:/Users/Jarvis/Desktop/523/Selected_front/' + file,cv2.IMREAD_GRAYSCALE)  #灰階
        im = cv2.GaussianBlur(im,(3,3),0)  #高斯模糊
        canny = cv2.Canny(im, 50, 150)  #邊緣檢測
        _,im = cv2.threshold(im, 128, 255, cv2.THRESH_BINARY) #二值化
        moment = cv2.moments(im)
        huMoments = cv2.HuMoments(moment)
        print("{}: ".format(filename+file),end='')
        for i in range(0,7):
            if showLogTransformedHuMoments:
                print("{:.5f}".format(-1*copysign(1.0,huMoments[i])*log10(abs(huMoments[i]))),end=' ')
            else:
                print("{:.5f}".format(huMoments[i]),end=' ')
        print()
        
main()

引用網址:https://home.gamer.com.tw/TrackBack.php?sn=5160609
All rights reserved. 版權所有,保留一切權利

相關創作

留言共 0 篇留言

我要留言提醒:您尚未登入,請先登入再留言

喜歡★mysecret20w 可決定是否刪除您的留言,請勿發表違反站規文字。

前一篇:Python openc... 後一篇:Python 讀取 cs...

追蹤私訊切換新版閱覽

作品資料夾

ulkbo你呀
可以來跟我說早安安嗎 https://www.twitch.tv/hokolala6969看更多我要大聲說昨天10:15


face基於日前微軟官方表示 Internet Explorer 不再支援新的網路標準,可能無法使用新的應用程式來呈現網站內容,在瀏覽器支援度及網站安全性的雙重考量下,為了讓巴友們有更好的使用體驗,巴哈姆特即將於 2019年9月2日 停止支援 Internet Explorer 瀏覽器的頁面呈現和功能。
屆時建議您使用下述瀏覽器來瀏覽巴哈姆特:
。Google Chrome(推薦)
。Mozilla Firefox
。Microsoft Edge(Windows10以上的作業系統版本才可使用)

face我們了解您不想看到廣告的心情⋯ 若您願意支持巴哈姆特永續經營,請將 gamer.com.tw 加入廣告阻擋工具的白名單中,謝謝 !【教學】