通过cv2输出左右眼视差图

 

# 遮挡关系因远近引起,
# 生成训练集, 生成10张 图片 
# 每张图片里有5个矩形,实心,彩色


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)
    


   
    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)]  = np.random.randint(100)                                                      # 对于每个矩形,准备一个深度(  与摄像头的距离 )
        z_depth[(i-1)]  = np.random.randint(100)                                                      # 对于每个矩形,准备一个深度(  与摄像头的距离 )
        # print (z_depth[i])
    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值超出(0,255),     [200, 399]列表形式时,也会引发该错误,转成tuple
        
        
    cv2.imwrite (("imgL"+ str(n).zfill(5) +".png"), imgL )    # ===================================保存左眼图片
    cv2.imwrite (("imgR"+ str(n).zfill(5) +".png"), imgR )    # ===================================保存右眼图片

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


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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值