最终粗糙版233
@ -58,7 +58,8 @@ def getFrameRate(cap):
|
|||||||
def getDepthMap(imgL, imgR):
|
def getDepthMap(imgL, imgR):
|
||||||
|
|
||||||
# stereo = cv2.StereoBM_create(numDisparity = 32, blockSize = 3) # 速度快,准确性较低,单通道
|
# stereo = cv2.StereoBM_create(numDisparity = 32, blockSize = 3) # 速度快,准确性较低,单通道
|
||||||
stereo = cv2.StereoSGBM_create(minDisparity = -16, numDisparities = 48, blockSize = 5, P1=320, P2=1280) # 速度稍慢,准确性较高,多通道
|
stereo = cv2.StereoSGBM_create(
|
||||||
|
minDisparity=-16, numDisparities=48, blockSize=5, P1=320, P2=1280) # 速度稍慢,准确性较高,多通道
|
||||||
return stereo.compute(imgL, imgR)
|
return stereo.compute(imgL, imgR)
|
||||||
|
|
||||||
|
|
||||||
@ -83,10 +84,14 @@ def getMotionVector(prvs, next):
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cap = openVid()
|
cap = openVid()
|
||||||
isDemo = int(input("is Demo(0/1)?"))
|
isDemo = int(input("is Demo(0/1)?"))
|
||||||
|
calcMod = int(input("calc optimize potential?"))
|
||||||
frameRate = getFrameRate(cap)
|
frameRate = getFrameRate(cap)
|
||||||
frameCount = getFrameCount(cap)
|
frameCount = getFrameCount(cap)
|
||||||
framesCalculated = 0
|
framesCalculated = 0
|
||||||
|
framesOptimized = 0
|
||||||
framesComfort = []
|
framesComfort = []
|
||||||
|
framesComfortOptimized = []
|
||||||
|
|
||||||
isSuccess, img = cap.read()
|
isSuccess, img = cap.read()
|
||||||
if not isSuccess:
|
if not isSuccess:
|
||||||
print("video read error.")
|
print("video read error.")
|
||||||
@ -140,7 +145,8 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# 运动矢量大小的众数,一般为0,若较大,说明画面中存在较大面积的快速运动,可能不适
|
# 运动矢量大小的众数,一般为0,若较大,说明画面中存在较大面积的快速运动,可能不适
|
||||||
Mode_motionMag = stats.mode(hsv[..., 2].reshape(-1))[0][0]
|
Mode_motionMag = stats.mode(hsv[..., 2].reshape(-1))[0][0]
|
||||||
print("Mode motionMag: ", Mode_motionMag) # 大于0则不适,越大越不适,权重0.2,0到30归一化为0.1到0.15,大于60为0.2
|
# 大于0则不适,越大越不适,权重0.2,0到30归一化为0.1到0.15,大于30为0.2
|
||||||
|
print("Mode motionMag: ", Mode_motionMag)
|
||||||
if Mode_motionMag > 0:
|
if Mode_motionMag > 0:
|
||||||
if Mode_motionMag > 30:
|
if Mode_motionMag > 30:
|
||||||
comfort -= 0.2
|
comfort -= 0.2
|
||||||
@ -165,18 +171,50 @@ if __name__ == "__main__":
|
|||||||
disparity_Positive = disparity.copy()
|
disparity_Positive = disparity.copy()
|
||||||
disparity_Positive[disparity_Positive < 0] = 0
|
disparity_Positive[disparity_Positive < 0] = 0
|
||||||
|
|
||||||
# 负视差的像素的所占比例,大于0.25时比较不适,权重0.15
|
# 负视差的像素的所占比例,大于0.2时比较不适,权重0.15,0.2到0.4归一化为0.05到0.1,大于0.4为0.15
|
||||||
PCT_disparity_Positive = np.count_nonzero(disparity_Positive)/disparity_Positive.shape[0]/disparity_Positive.shape[1]
|
PCT_disparity_Positive = np.count_nonzero(
|
||||||
|
disparity_Positive)/disparity_Positive.shape[0]/disparity_Positive.shape[1]
|
||||||
print("close pixels percetage:", round(PCT_disparity_Positive, 3))
|
print("close pixels percetage:", round(PCT_disparity_Positive, 3))
|
||||||
if PCT_disparity_Positive > 0.25:
|
if PCT_disparity_Positive > 0.2:
|
||||||
|
if PCT_disparity_Positive > 0.4:
|
||||||
comfort -= 0.15
|
comfort -= 0.15
|
||||||
|
orgn_cmft = -0.15
|
||||||
|
else:
|
||||||
|
comfort -= ((PCT_disparity_Positive - 0.2) / 4 + 0.05)
|
||||||
|
orgn_cmft = -((PCT_disparity_Positive - 0.2) / 4 + 0.05)
|
||||||
|
if calcMod:
|
||||||
|
# 视差重映射并重新计算
|
||||||
|
# 实际并不写入文件,只估计此项提升值
|
||||||
|
trans = np.float32([[1,0,20],[0,1,0]])
|
||||||
|
imgR_Mod = cv2.warpAffine(imgR, trans, imgR.shape[:2])
|
||||||
|
imgR_Mod = imgR_Mod.transpose((1,0,2))
|
||||||
|
disparity_Mod = getDepthMap(imgL, imgR_Mod)
|
||||||
|
disparity_Positive = disparity_Mod.copy()
|
||||||
|
disparity_Positive[disparity_Positive < 0] = 0
|
||||||
|
PCT_disparity_Positive = np.count_nonzero(
|
||||||
|
disparity_Positive)/disparity_Positive.shape[0]/disparity_Positive.shape[1]
|
||||||
|
print("Modified close pixels percetage:", round(PCT_disparity_Positive, 3))
|
||||||
|
if PCT_disparity_Positive > 0.2:
|
||||||
|
if PCT_disparity_Positive > 0.4:
|
||||||
|
mod_cmft = -0.15
|
||||||
|
else:
|
||||||
|
mod_cmft = -((PCT_disparity_Positive - 0.2) / 4 + 0.05)
|
||||||
|
else:
|
||||||
|
mod_cmft = 0
|
||||||
|
comfort_optimized = round(mod_cmft - orgn_cmft, 3)
|
||||||
|
framesOptimized += 1
|
||||||
|
framesComfortOptimized.append(comfort_optimized)
|
||||||
|
print("comfort optimized by ", comfort_optimized)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 存在运动的像素点的视差平均值
|
# 存在运动的像素点的视差平均值
|
||||||
movingPixels = hsv[..., 2]
|
movingPixels = hsv[..., 2]
|
||||||
movingPixels[movingPixels < 10] = 0 # 小于10的运动认为是静止
|
movingPixels[movingPixels < 10] = 0 # 小于10的运动认为是静止
|
||||||
movingPixels[movingPixels > 0] = 1
|
movingPixels[movingPixels > 0] = 1
|
||||||
movingDepth = np.multiply(disparity, movingPixels)
|
movingDepth = np.multiply(disparity, movingPixels)
|
||||||
AVG_movingDepth = round(np.sum(movingDepth)/np.count_nonzero(movingDepth))
|
AVG_movingDepth = round(np.sum(movingDepth) /
|
||||||
|
np.count_nonzero(movingDepth))
|
||||||
print("AVG movingDepth: ", AVG_movingDepth) # 大于5时不适,权重0.15
|
print("AVG movingDepth: ", AVG_movingDepth) # 大于5时不适,权重0.15
|
||||||
if AVG_movingDepth > 5:
|
if AVG_movingDepth > 5:
|
||||||
comfort -= 0.15
|
comfort -= 0.15
|
||||||
@ -189,8 +227,6 @@ if __name__ == "__main__":
|
|||||||
print("TotalComfort: ", round(sum(framesComfort)/framesCalculated, 2))
|
print("TotalComfort: ", round(sum(framesComfort)/framesCalculated, 2))
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 当为demo模式时显示当前帧画面、运动矢量图和景深图
|
# 当为demo模式时显示当前帧画面、运动矢量图和景深图
|
||||||
if isDemo:
|
if isDemo:
|
||||||
# 显示当前帧
|
# 显示当前帧
|
||||||
@ -223,5 +259,6 @@ if __name__ == "__main__":
|
|||||||
prvs = next # 当前帧覆盖上一帧,继续计算
|
prvs = next # 当前帧覆盖上一帧,继续计算
|
||||||
print("TotalFrameCalculated: ", framesCalculated)
|
print("TotalFrameCalculated: ", framesCalculated)
|
||||||
print("TotalComfort: ", round(sum(framesComfort)/framesCalculated, 2))
|
print("TotalComfort: ", round(sum(framesComfort)/framesCalculated, 2))
|
||||||
|
if calcMod:
|
||||||
|
print("estimated comfort optimization potential:", round(sum(framesComfortOptimized)/framesOptimized, 3))
|
||||||
print("success")
|
print("success")
|
||||||
|
|
||||||
|
BIN
pic/10.jpg
Before Width: | Height: | Size: 527 KiB |
BIN
pic_cn/小巷.jpg
Before Width: | Height: | Size: 238 KiB |
BIN
pic_cn/恐龙.jpg
Before Width: | Height: | Size: 922 KiB |
BIN
pic_cn/林中小径.jpg
Before Width: | Height: | Size: 924 KiB |
BIN
pic_cn/校园.jpg
Before Width: | Height: | Size: 527 KiB |
BIN
pic_cn/楼梯.jpg
Before Width: | Height: | Size: 1.0 MiB |
BIN
pic_cn/渡口.jpg
Before Width: | Height: | Size: 594 KiB |
BIN
pic_cn/白鸽.jpg
Before Width: | Height: | Size: 395 KiB |
BIN
pic_cn/花.jpg
Before Width: | Height: | Size: 165 KiB |
BIN
pic_cn/铁塔.jpg
Before Width: | Height: | Size: 653 KiB |
BIN
pic_cn/雪花.jpg
Before Width: | Height: | Size: 417 KiB |