# --*-- coding:utf-8 --*--
import math
import cv2
import os
import math
import numpy as np
from utils.rgbd_util import *
from utils.getCameraParam import *
'''
must use 'COLOR_BGR2GRAY' here, or you will get a different gray-value with what MATLAB gets.
'''
'''
C: Camera matrix
D: Depth image, the unit of each element in it is "meter"
RD: Raw depth image, the unit of each element in it is "meter"
'''
def getHHA(C, D, RD):
missingMask = (RD == 0);
pc, N, yDir, h, pcRot, NRot = processDepthImage(D * 100, missingMask, C);
tmp = np.multiply(N, yDir)
acosValue = np.minimum(1, np.maximum(-1, np.sum(tmp, axis=2)))
angle = np.array([math.degrees(math.acos(x)) for x in acosValue.flatten()])
angle = np.reshape(angle, h.shape)
'''
Must convert nan to 180 as the MATLAB program actually does.
Or we will get a HHA image whose border region is different
with that of MATLAB program's output.
'''
angle[np.isnan(angle)] = 180
pc[:, :, 2] = np.maximum(pc[:, :, 2], 100)
I = np.zeros(pc.shape)
# opencv-python save the picture in BGR order.
I[:, :, 2] = 20000 / pc[:, :, 2]*6
I[:, :, 1] = h/20
I[:, :, 0] = (angle + 128 - 90) + 10
# print(np.isnan(angle))
'''
np.uint8 seems to use 'floor', but in matlab, it seems to use 'round'.
So I convert it to integer myself.
'''
I = np.rint(I)
# np.uint8: 256->1, but in MATLAB, uint8: 256->255
I[I > 255] = 255
HHA = I.astype(np.uint8)
return HHA
if __name__ == "__main__":
for i in range(1448):
D = getImageD(i)
RD = getImageRD(i)
camera_matrix = getCameraParam('color')
print('max gray value: ', np.max(D)) # make sure that the image is in 'meter'
hha = getHHA(camera_matrix, D, RD)
# hha_complete = getHHA(camera_matrix, D, D)
cv2.imwrite('HHA/%d.png' % (i), hha)
# cv2.imwrite('hha_complete/%d.png' % (i), hha_complete)
''' multi-peocessing example '''
'''
from multiprocessing import Pool
def generate_hha(i):
# generate hha for the i-th image
return
processNum = 16
pool = Pool(processNum)
for i in range(img_num):
print(i)
pool.apply_async(generate_hha, args=(i,))
pool.close()
pool.join()
'''
粉兔L
- 粉丝: 454
- 资源: 1
最新资源
- MATLAB代码:基于分布式ADMM算法的考虑碳排放交易的电力系统优化调度研究 关键词:分布式调度 ADMM算法 交替方向乘子法 碳排放 最优潮流 仿真平台:MATLAB+CPLEX GUROBI
- 基于二阶自抗扰ADRC的轨迹跟踪控制,对车辆的不确定性和外界干扰具有一定抗干扰性,基于carsim和simulink仿真 跟踪轨迹为双移线,效果良好,有对应复现资料,是学习自抗扰技术快速入门很好的资料
- 程序名称:转向设计计算程序 开发平台:基于matlab平台 计算内容:阿克曼转角,转弯半径,转向阻力矩,回正力矩,转向主参数,转向传动比,力矩波动,转向梯形,EPS匹配,HPS匹配,齿轮齿条传动比,循
- 基于python的网页自动化工具项目全套技术资料100%好用.zip
- MATLAB【逆变器二次调频模型】 微电网分布式电源逆变器DROOP控制二次调频模型,加入二次控制实现二次调频控制,及二次调压控制,程序可实现上图功能,工况有所改变 需要matlab2021A版
- 抢购软件:快速复制信息
- 纯电动汽车再生制动策略,Cruise和Simulink联合仿真,提供Cruise整车模型和simuink策略模型,有详细解析文档,可运行
- 单机无穷大系统发生各类(三相短路,单相接地,两相接地,两相相间短路)等短路故障,各类(单相断线,两相断线,三相断线)等断线故障,暂态稳定仿真分析
- 微信文章爬虫项目全套技术资料100%好用.zip
- 基于动态窗口算法的AGV仿真避障 可设置起点目标点,设置地图,设置移动障碍物起始点目标点,未知静态障碍物 动态窗口方法(DynamicWindowApproach) 是一种可以实现实时避障的局部规划算
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈