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

資源簡介

PY語言對大米進行識別計數,基礎的數字圖像處理

資源截圖

代碼片段和文件信息

import?cv2
import?numpy?as?np

#?4鄰域的連通域和?8鄰域的連通域
#?[row?col]
NEIGHBOR_HOODS_4?=?True
OFFSETS_4?=?[[0?-1]?[-1?0]?[0?0]?[1?0]?[0?1]]

NEIGHBOR_HOODS_8?=?False
OFFSETS_8?=?[[-1?-1]?[0?-1]?[1?-1]
?????????????[-1??0]?[0??0]?[1??0]
?????????????[-1??1]?[0??1]?[1??1]]



def?reorganize(binary_img:?np.array):
????index_map?=?[]
????points?=?[]
????index?=?-1
????rows?cols?=?binary_img.shape
????for?row?in?range(rows):
????????for?col?in?range(cols):
????????????var?=?binary_img[row][col]
????????????if?var?????????????????continue
????????????if?var?in?index_map:
????????????????index?=?index_map.index(var)
????????????????num?=?index?+?1
????????????else:
????????????????index?=?len(index_map)
????????????????num?=?index?+?1
????????????????index_map.append(var)
????????????????points.append([])
????????????binary_img[row][col]?=?num
????????????points[index].append([row?col])
????return?binary_img?points



def?neighbor_value(binary_img:?np.array?offsets?reverse=False):
????rows?cols?=?binary_img.shape
????label_idx?=?0
????rows_?=?[0?rows?1]?if?reverse?==?False?else?[rows-1?-1?-1]
????cols_?=?[0?cols?1]?if?reverse?==?False?else?[cols-1?-1?-1]
????for?row?in?range(rows_[0]?rows_[1]?rows_[2]):
????????for?col?in?range(cols_[0]?cols_[1]?cols_[2]):
????????????label?=?256
????????????if?binary_img[row][col]?????????????????continue
????????????for?offset?in?offsets:
????????????????neighbor_row?=?min(max(0?row+offset[0])?rows-1)
????????????????neighbor_col?=?min(max(0?col+offset[1])?cols-1)
????????????????neighbor_val?=?binary_img[neighbor_row?neighbor_col]
????????????????if?neighbor_val?????????????????????continue
????????????????label?=?neighbor_val?if?neighbor_val?????????????if?label?==?255:
????????????????label_idx?+=?1
????????????????label?=?label_idx
????????????binary_img[row][col]?=?label
????return?binary_img

def?recursive_seed(binary_img:?np.array?seed_row?seed_col?offsets?num?max_num=100):
????rows?cols?=?binary_img.shape
????binary_img[seed_row][seed_col]?=?num
????for?offset?in?offsets:
????????neighbor_row?=?min(max(0?seed_row+offset[0])?rows-1)
????????neighbor_col?=?min(max(0?seed_col+offset[1])?cols-1)
????????var?=?binary_img[neighbor_row][neighbor_col]
????????if?var?????????????continue
????????binary_img?=?recursive_seed(binary_img?neighbor_row?neighbor_col?offsets?num?max_num)
????return?binary_img

#?binary_img:?bg-0?object-255;?int
def?Two_Pass(binary_img?neighbor_hoods?max_num=100):
????if?neighbor_hoods?==?NEIGHBOR_HOODS_4:
????????offsets?=?OFFSETS_4
????elif?neighbor_hoods?==?NEIGHBOR_HOODS_8:
????????offsets?=?OFFSETS_8
????else:
????????raise?ValueError

????num?=?1
????rows?cols?=?binary_img.shape
????for?row?in?range(rows):
????????for?col?in?range(cols):
????????????var?=?binary_img[row][col]
????????????if?v

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????7898??2020-10-05?15:45??代碼\task1.png
?????文件????????3680??2020-10-05?16:42??代碼\test.py

評論

共有 條評論