91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 7.41MB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2023-09-22
  • 語言: 其他
  • 標(biāo)簽:

資源簡(jiǎn)介

儀表數(shù)據(jù)讀取,數(shù)據(jù)儀表數(shù)據(jù)的圖像輸出刻度值,其中使用了OpenCV和k-means算法

資源截圖

代碼片段和文件信息

import?cv2
import?numpy?as?np
from?sklearn.cluster?import?KMeans
from?sklearn.utils?import?shuffle
from?math?import?cos?pi?sin
from?計(jì)算刻度值?import?get_rad_val

methods?=?[‘cv2.TM_CCOEFF‘?‘cv2.TM_CCOEFF_NORMED‘?‘cv2.TM_CCORR‘
???????????????‘cv2.TM_CCORR_NORMED‘?‘cv2.TM_SQDIFF‘?‘cv2.TM_SQDIFF_NORMED‘]
method?=?cv2.TM_CCOEFF

def?get_match_rect(templateimgmethod):
????‘‘‘獲取模板匹配的矩形的左上角和右下角的坐標(biāo)‘‘‘
????w?h?=?template.shape[1]template.shape[0]
????res?=?cv2.matchTemplate(img?template?method)
????mn_val?max_val?min_loc?max_loc?=?cv2.minMaxLoc(res)
????#?使用不同的方法,對(duì)結(jié)果的解釋不同
????if?method?in?[cv2.TM_SQDIFF?cv2.TM_SQDIFF_NORMED]:
????????top_left?=?min_loc
????else:
????????top_left?=?max_loc
????bottom_right?=?(top_left[0]?+?w?top_left[1]?+?h)
????return?top_leftbottom_right

def?get_center_point(top_leftbottom_right):
????‘‘‘傳入左上角和右下角坐標(biāo),獲取中心點(diǎn)‘‘‘
????c_x?c_y?=?((np.array(top_left)?+?np.array(bottom_right))?/?2).astype(np.int)
????return?c_xc_y

def?get_circle_field_color(imgcenterrthickness):
????‘‘‘獲取中心圓形區(qū)域的色值集‘‘‘
????temp=img.copy().astype(np.int)
????cv2.circle(tempcenterr-100thickness=thickness)
????return?img[temp?==?-100]

def?v2_by_center_circle(imgcolors):
????‘‘‘二值化通過中心圓的顏色集合‘‘‘
????for?i?in?range(img.shape[0]):
????????for?j?in?range(img.shape[1]):
????????????a?=?img[i?j]
????????????if?a?in?colors:
????????????????img[i?j]?=?0
????????????else:
????????????????img[i?j]?=?255

def?v2_by_k_means(img):
????‘‘‘使用k-means二值化‘‘‘
????original_img?=?np.array(img?dtype=np.float64)
????src?=?original_img.copy()
????delta_y?=?int(original_img.shape[0]?*?(0.4))
????delta_x?=?int(original_img.shape[1]?*?(0.4))
????original_img?=?original_img[delta_y:-delta_y?delta_x:-delta_x]
????h?w?d?=?src.shape
????print(w?h?d)
????dts?=?min([w?h])
????print(dts)
????r2?=?(dts?/?2)?**?2
????c_x?c_y?=?w?/?2?h?/?2
????a:?np.ndarray?=?original_img[:?:?0:3].astype(np.uint8)
????#?獲取尺寸(寬度、長度、深度)
????height?width?=?original_img.shape[0]?original_img.shape[1]
????depth?=?3
????print(depth)
????image_flattened?=?np.reshape(original_img?(width?*?height?depth))
????‘‘‘
????用K-Means算法在隨機(jī)中選擇1000個(gè)顏色樣本中建立64個(gè)類。
????每個(gè)類都可能是壓縮調(diào)色板中的一種顏色。
????‘‘‘
????image_array_sample?=?shuffle(image_flattened?random_state=0)
????estimator?=?KMeans(n_clusters=2?random_state=0)
????estimator.fit(image_array_sample)
????‘‘‘
????我們?yōu)樵紙D片的每個(gè)像素進(jìn)行類的分配。
????‘‘‘
????src_shape?=?src.shape
????new_img_flattened?=?np.reshape(src?(src_shape[0]?*?src_shape[1]?depth))
????cluster_assignments?=?estimator.predict(new_img_flattened)
????‘‘‘
????我們建立通過壓縮調(diào)色板和類分配結(jié)果創(chuàng)建壓縮后的圖片
????‘‘‘
????compressed_palette?=?estimator.cluster_centers_
????print(compressed_palette)
????a?=?np.apply_along_axis(func1d=lambda?x:?np.uint8(compressed_palette[x])?arr=cluster_assignments?axis=0)
????img?=?a.reshape(src_shape[0]?src_shape[1]?depth)
????print(compressed_palette[0?0])
????threshold?=?(compressed_palette[0

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????1097??2019-03-19?10:26??計(jì)算刻度值.py
?????文件????????8735??2019-03-19?09:48??模板匹配法.py
?????目錄???????????0??2019-03-14?11:23??test\
?????文件??????232776??2018-04-18?18:23??test\?(1).jpg
?????文件??????214534??2018-04-05?13:00??test\?(10).jpg
?????文件??????218869??2018-04-05?18:37??test\?(11).jpg
?????文件??????209028??2018-04-06?17:19??test\?(12).jpg
?????文件??????198367??2018-04-07?09:38??test\?(13).jpg
?????文件??????233799??2018-04-07?15:15??test\?(14).jpg
?????文件??????209590??2018-04-07?17:32??test\?(15).jpg
?????文件??????229510??2018-04-08?10:18??test\?(16).jpg
?????文件??????215287??2018-04-08?16:49??test\?(17).jpg
?????文件??????215923??2018-04-10?10:17??test\?(18).jpg
?????文件??????200903??2018-04-11?09:14??test\?(19).jpg
?????文件??????233689??2018-03-30?17:46??test\?(2).jpg
?????文件??????195924??2018-04-13?17:13??test\?(20).jpg
?????文件??????197012??2018-04-14?16:41??test\?(21).jpg
?????文件??????189283??2018-04-14?19:23??test\?(22).jpg
?????文件??????198637??2018-04-15?11:49??test\?(23).jpg
?????文件??????209585??2018-04-15?15:39??test\?(24).jpg
?????文件??????175260??2018-04-15?19:21??test\?(25).jpg
?????文件??????214954??2018-04-16?10:20??test\?(26).jpg
?????文件??????176198??2018-04-16?19:21??test\?(27).jpg
?????文件??????197078??2018-04-17?09:20??test\?(28).jpg
?????文件??????219506??2018-04-17?10:56??test\?(29).jpg
?????文件??????213962??2018-03-31?09:30??test\?(3).jpg
?????文件??????226911??2018-04-17?19:00??test\?(30).jpg
?????文件??????215344??2018-04-18?10:01??test\?(31).jpg
?????文件??????248144??2018-03-31?14:44??test\?(4).jpg
?????文件??????181730??2018-04-01?09:42??test\?(5).jpg
?????文件??????238052??2018-04-03?18:00??test\?(6).jpg
............此處省略4個(gè)文件信息

評(píng)論

共有 條評(píng)論