我有一个巨大的图像数据集,不适合内存.我想计算mean和standard deviation从磁盘加载图像.
我目前正在尝试使用维基百科上的这个算法.
# for a new value newValue, compute the new count, new mean, the new M2.
# mean accumulates the mean of the entire dataset
# M2 aggregates the squared distance from the mean
# count aggregates the amount of samples seen so far
def update(existingAggregate, newValue):
(count, mean, M2) = existingAggregate
count = count + 1
delta = newValue - mean
mean = mean + delta / count
delta2 = newValue …Run Code Online (Sandbox Code Playgroud) 我编写了下面的代码来检测图像中的 3D 形状,并且它工作正常。
现在我需要检测形状内的颜色并计算它们。
谁能指出我应该从哪里开始进行颜色检测?
下面的形状检测代码,也许会有用:
import cv2
import numpy as np
cv2.imshow('Original Image',rawImage)
cv2.waitKey(0)
hsv = cv2.cvtColor(rawImage, cv2.COLOR_BGR2HSV)
cv2.imshow('HSV Image',hsv)
cv2.waitKey(0)
hue ,saturation ,value = cv2.split(hsv)
cv2.imshow('Saturation Image',saturation)
cv2.waitKey(0)
retval, thresholded = cv2.threshold(saturation, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
cv2.imshow('Thresholded Image',thresholded)
cv2.waitKey(0)
medianFiltered = cv2.medianBlur(thresholded,5)
cv2.imshow('Median Filtered Image',medianFiltered)
cv2.waitKey(0)
cnts, hierarchy = cv2.findContours(medianFiltered, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for c in cnts:
# compute the center of the contour
M = cv2.moments(c)
cX = int(M["m10"] / M["m00"])
cY = int(M["m01"] / M["m00"])
first …Run Code Online (Sandbox Code Playgroud)