最终粗糙版233

This commit is contained in:
jiacai_wang 2019-05-27 14:46:19 +08:00
parent 6189b6b6e9
commit 1b8b8c11cf
21 changed files with 58 additions and 21 deletions

View File

@ -58,7 +58,8 @@ def getFrameRate(cap):
def getDepthMap(imgL, imgR):
# 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)
@ -83,10 +84,14 @@ def getMotionVector(prvs, next):
if __name__ == "__main__":
cap = openVid()
isDemo = int(input("is Demo(0/1)?"))
calcMod = int(input("calc optimize potential?"))
frameRate = getFrameRate(cap)
frameCount = getFrameCount(cap)
framesCalculated = 0
framesOptimized = 0
framesComfort = []
framesComfortOptimized = []
isSuccess, img = cap.read()
if not isSuccess:
print("video read error.")
@ -140,7 +145,8 @@ if __name__ == "__main__":
# 运动矢量大小的众数一般为0若较大说明画面中存在较大面积的快速运动可能不适
Mode_motionMag = stats.mode(hsv[..., 2].reshape(-1))[0][0]
print("Mode motionMag: ", Mode_motionMag) # 大于0则不适越大越不适权重0.20到30归一化为0.1到0.15大于60为0.2
# 大于0则不适越大越不适权重0.20到30归一化为0.1到0.15大于30为0.2
print("Mode motionMag: ", Mode_motionMag)
if Mode_motionMag > 0:
if Mode_motionMag > 30:
comfort -= 0.2
@ -148,13 +154,13 @@ if __name__ == "__main__":
comfort -= (Mode_motionMag/600 + 0.1)
# 景深的标准差若偏大说明景深范围较大可能不适但同时也是3D感更强的特征
STD_depth = round(np.std(disparity),2)
STD_depth = round(np.std(disparity), 2)
print("STD depth: ", STD_depth) # 大于130时略不适权重为0.15
if STD_depth > 130:
comfort -= 0.15
# 运动矢量大小的标准差,若偏大说明各部分运动比较不一致,可能需要结合运动矢量的方向作进一步判断,若存在较复杂的运动形式,则可能不适
STD_motionMag = round(np.std(hsv[...,2]),2)
STD_motionMag = round(np.std(hsv[..., 2]), 2)
print("STD motionMag: ", STD_motionMag) # 大于20时略不适权重为0.1
if STD_motionMag > 20:
comfort -= 0.1
@ -165,18 +171,50 @@ if __name__ == "__main__":
disparity_Positive = disparity.copy()
disparity_Positive[disparity_Positive < 0] = 0
# 负视差的像素的所占比例大于0.25时比较不适权重0.15
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))
if PCT_disparity_Positive > 0.25:
# 负视差的像素的所占比例大于0.2时比较不适权重0.150.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]
print("close pixels percetage:", round(PCT_disparity_Positive, 3))
if PCT_disparity_Positive > 0.2:
if PCT_disparity_Positive > 0.4:
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 > 0] = 1
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
if AVG_movingDepth > 5:
comfort -= 0.15
@ -186,11 +224,9 @@ if __name__ == "__main__":
print()
print("CurFrameComfort: ", comfort)
print("TotalComfort: ", round(sum(framesComfort)/framesCalculated,2))
print("TotalComfort: ", round(sum(framesComfort)/framesCalculated, 2))
print()
# 当为demo模式时显示当前帧画面、运动矢量图和景深图
if isDemo:
# 显示当前帧
@ -222,6 +258,7 @@ if __name__ == "__main__":
input("press Enter to continue")
prvs = next # 当前帧覆盖上一帧,继续计算
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")

BIN
pic/1.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 395 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 527 KiB

BIN
pic/2.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 594 KiB

BIN
pic/3.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 165 KiB

BIN
pic/4.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 922 KiB

BIN
pic/5.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 924 KiB

BIN
pic/6.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 MiB

BIN
pic/7.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 417 KiB

BIN
pic/8.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 653 KiB

BIN
pic/9.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 922 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 924 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 527 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 594 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 395 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 165 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 653 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 417 KiB