temp 自动输出简单的 视差图和深度图

# 遮挡关系因远近引起,
# 生成训练集, 生成10张 图片 
# 每张图片里有5个矩形,实心,彩色
#   输出图片深度信息 (label) 
#             todo   太多数据类型转换       --- .astype(    np.uint8  )                  --- z_depth  = int(z_depth_sort[i] *3 )
#             todo z_depth  = int(z_depth_sort[i] *3 )           是否会溢出 ??   看样子伪色彩已经削峰了
#        todo  视差数据,转换深度数据 , 转换公式 =??


import cv2
import numpy as np

for n in range (1,11):                                 #  =======================================================生成图片的数量
    print(n)
    
    x=[0]*100     # debug   <<<<<<<<<<<<<<<<  x=x[] invalid syntax ,    debug  <<<<<<<<<<<<<<<<  x= []  list assignment index out of range
    y=[0]*100
    z_depth=[0]*10
    # print( z_depth)
        
        
    imgL             =np.zeros(( 480,640,3),np.uint8)                                                         # ========准备画布 480,640
    imgR            =np.zeros(( 480,640,3),np.uint8)
    imgLabelR=np.zeros(( 480,640,3),np.uint8)


   
    for i in range(1,11,2):                              # ==========================================================每张图片中矩形数量     准备2 x n个点,代表n个矩形
        x[i], y[i] = np.random.randint(300, size=2 )                                                   # debug   x[i],   y[i] = np.random.randint(100, size=2  )  <<<<<<<<<<<<<<<< IndexError: list assignment index out of range
        x[i+1], y[i+1]= np.random.randint(600, size=2 )                                          #      x(i+1),   y(i+1)= np.random.randint(400, size=2  )  SyntaxError: can't assign to function call
        # print( x[i], y[i ] )
        print("==========",i+1)  
        z_depth[(i-1)], z_depth[(i)]      = np.random.randint(100, size=2) .astype(    np.uint8  )            # 对于每个矩形,准备一个深度(  与摄像头的距离 )             
                                                                                                                                                                                                #  debug  单个数字不能用.astype(    np.uint8  )  , 一个数组可以用 .   <<<<<<<<<<<<<< AttributeError: 'int' object has no attribute 'astype'     ---      z_depth[(i)]      = np.random.randint(100) .astype(    np.uint8  )   
    print (z_depth)
    z_depth_sort=np.sort(z_depth)
    print("这是整理以后的深度排序============",z_depth_sort)

    for i in range(1,11,2):                                                                                                     # ============在画布上画出所有矩形
        #R_color,G_color ,B_color = np.random.randint(  255, size=3 ).astype(    np.uint8  )     #  随机产生一种颜色 ,也可以写成 np.random.randint(  255, size=3 ,dtype=int )  
        R_color,G_color ,B_color =  np.random.randint(  255, size=3 ).astype(np.uint8)  
        R_color  = int(R_color)
        G_color  = int(G_color)
        B_color  = int(B_color)
        #print(type  (R_color )  )                                                                                              # debug <<<<<<< 获得整数的类型
        #print(type  (R_color.astype(np.uint8()) ) 
        print("x[i],-----x[i]-z_depth_sort[i]----------",   x[i],x[i]-z_depth_sort[i]  )
        cv2.rectangle(imgL,( x[i], y[i] ),( x[i+1], y[i+1 ] ),  (R_color,G_color ,B_color),  -1)                                                                   # 图片名,    左上顶点和右下顶点,颜色,线宽
        cv2.rectangle(imgR,( x[i]-z_depth_sort[i], y[i]  ),( x[i+1]-z_depth_sort[i], y[i+1]),  (R_color,G_color ,B_color),-1)    # 图片名,    左上顶点和右下顶点,颜色,线宽

        
        
        
        
        # debug <<<<<<<<<<<<<<, - Scalar value for argument 'color' is not numeric      color值超出 np.uint8  (0,255),     [200, 399]列表形式时,也会引发该错误,转成tuple
        print(" type(z_depth_sort[i])----------", type(z_depth_sort[i]   )  )
        print("type(R_color )----------",   type(R_color) )
        z_depth  = int(z_depth_sort[i] *3 )                                                             #  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<todo 是否会溢出 ??
        cv2.rectangle( imgLabelR,        ( x[i]-z_depth_sort[i], y[i]  ),       ( x[i+1]-z_depth_sort[i], y[i+1]),          (z_depth ,z_depth ,z_depth ),       -1) 
                   #    参数(       图片名                 x1                                 y1                   x2                                           y2                        r                g                b                        线宽=色块 )
        
        
        
        
    depthGrayR=cv2.cvtColor(imgLabelR,cv2.COLOR_BGR2GRAY)     
    depthColorR = cv2.applyColorMap(depthGrayR, cv2.COLORMAP_JET)                      # COLORMAP_JET            = 2, 蓝到红
                                                                                                                                                                         # COLORMAP_RAINBOW = 4,红到蓝
    cv2.rectangle(imgL,( x[i], y[i] ),( x[i+1], y[i+1 ] ),  (R_color,G_color ,B_color),  -1)                                                                 #   左上顶点和右下顶点,颜色,线宽

    
    
    
    cv2.imwrite (("imgL"+ str(n).zfill(5) +".png"), imgL )                                      # ===================================保存左眼图片
    cv2.imwrite (("imgR"+ str(n).zfill(5) +".png"), imgR )                                     # ===================================保存右眼图片
    cv2.imwrite (("depthColorR "+ str(n).zfill(5) +".png"), depthColorR )     # ===================================保存右眼  深度label 图片
    
    
    
    
    

        

'''    
    cv2.imshow("imageL", imgL)                          # 显示图片
    cv2.imshow("imageR", imgR)


    cv2.waitKey (0)                                                       # 等待键盘输入(显示图片的时间)
    cv2.destroyAllWindows()                                    # 回收资源
'''

 

# 生成训练集, 生成10张 图片
 
#      todo   太多数据类型转换       --- .astype(    np.uint8  )                  --- z_depth  = int(z_depth_sort[i] *3 )
#      todo z_depth  = int(z_depth_sort[i] *3 )           是否会溢出 ??   看样子伪色彩已经削峰了
#      todo  视差数据,转换深度数据 , 转换公式 =??

# todo  立体视觉的关键信息: 
#1- 遮挡关系, 
#2- 左右眼视差  ,
#3-(横x、竖y、深度z)透视引导线(路,墙线,地面线), 
#4- 常见物体远小近大的对比关系。  
#5  相对运动速度(伪3D卷轴游戏)

# 端到端的方法, 难度逐渐加大
#  从视差图 到垂直边线深度图,到矩形深度图
#  从视差图 到深度图,
#  从视差图 到分割图,到深度图

# 设计一个网络,有多种难度,简单的是对视差堆叠图 的cnn做微调,难的是 用cnn等架构做end to end 架构。 简单的是仅仅判别前后关系, 难的是直接判别与摄像头位置的距离。

# 如何设计网络,除了架构,最关键的是设计误差函数,即如何评价经过网络正向计算后的数据。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值