You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
4.5KB

  1. # import cv2,os
  2. # import time
  3. # import subprocess as sp
  4. # # 图片合并
  5. # # def readImage():
  6. # # p1 = cv2.imread("C:/Users/chenyukun/Pictures/Camera Roll/a.jpg")
  7. # # p2 = cv2.imread("C:/Users/chenyukun/Pictures/Camera Roll/b.jpg")
  8. # # ret = cv2.add(p1, p2)
  9. # # cv2.imwrite(r"C:\Users\chenyukun\Pictures\Camera Roll\aa.jpg", ret)
  10. # #
  11. # # readImage()
  12. # # https://opencv.apachecn.org/#/docs/4.0.0/2.1-tutorial_py_image_display
  13. # if __name__ == "__main__":
  14. # # print(cv2.__version__)
  15. # # # 读取图像
  16. # # p1 = cv2.imread("C:/Users/chenyukun/Pictures/Camera Roll/a.jpg", 0) # 以灰度模式加载图像
  17. # # p2 = cv2.imread("C:/Users/chenyukun/Pictures/Camera Roll/b.jpg", 1) # **cv.IMREAD_COLOR**:加载彩色图像,任何图像的透明度都会被忽略,它是默认标志
  18. # # p3 = cv2.imread("C:/Users/chenyukun/Pictures/Camera Roll/b.jpg", -1) # 加载图像,包括 alpha 通道
  19. # # p4 = cv2.imread("C:/Users/chenyukun/Pictures/Camera Roll/a.jpg")
  20. # # p5 = cv2.imread("C:/Users/chenyukun/Pictures/Camera Roll/c.jpg")
  21. # # print(type(p5))
  22. # # ret = cv2.add(p4, p5)
  23. # # # 显示图像
  24. # # cv2.imshow('frame', p1)
  25. # # cv2.imshow('frame1', p2)
  26. # # cv2.imshow('frame2', p3)
  27. # # # 对显示窗口做调整,WINDOW_AUTOSIZE不可调整,WINDOW_NORMAL可调整窗口大小
  28. # # cv2.namedWindow('frame3', cv2.WINDOW_AUTOSIZE)
  29. # # cv2.imshow('frame3', ret)
  30. # # # 等待时间 按下任务键
  31. # # k = cv2.waitKey(1) & 0xFF
  32. # # if k == 27: #ESC退出
  33. # # cv2.destroyAllWindows()
  34. # # elif k == ord('s'): # 's' 保存退出
  35. # # # 保存图像
  36. # # cv2.imwrite("C:/Users/chenyukun/Pictures/Camera Roll/d.jpg", ret)
  37. # # cv2.destroyAllWindows()
  38. #
  39. #
  40. #
  41. # # 视频入门
  42. # try:
  43. # cap = cv2.VideoCapture("rtmp://live.play.t-aaron.com/live/THSAf_hd") # 0:表示连接一台摄像机
  44. # print(cap.isOpened())
  45. # print(cap)
  46. # except Exception as e:
  47. # print(e)
  48. # raise e
  49. # print("aaaa")
  50. # # 有时,cap 可能没有初始化 capture。在这种情况下,此代码显示错误。你可以通过该方法 cap.isOpened() 检查它是否初始化。
  51. # # 如果它是 True,那么是好的,否则用 cap.open() 打开在使用。
  52. # fps = int(cap.get(cv2.CAP_PROP_FPS))
  53. # width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
  54. # height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
  55. # print(fps,width,height)
  56. # # # 设置宽
  57. # # print(cap.set(cv2.CAP_PROP_FRAME_WIDTH, 320))
  58. # # # 设置高
  59. # # print(cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 240))
  60. #
  61. # # 声明编码器和创建 VideoWrite 对象
  62. # fourcc = cv2.VideoWriter_fourcc(*'mp4v')
  63. # out = cv2.VideoWriter('/home/DATA/dsp/ai/video/eee.mp4',fourcc, fps, (width, height))
  64. # command=['/usr/bin/ffmpeg',
  65. # '-y', # 覆盖输出文件
  66. # '-f', 'rawvideo', # 强迫采用格式fmt
  67. # '-vcodec','rawvideo',
  68. # '-pix_fmt', 'bgr24',
  69. # '-s', "{}x{}".format(640, 480),# 图片分辨率
  70. # '-r', str(25.0),# 视频帧率
  71. # '-i', '-',
  72. # '-c:v', 'libx264',
  73. # '-pix_fmt', 'yuv420p',
  74. # '-preset', 'ultrafast',
  75. # '-f', 'flv',
  76. # "rtmp://live.push.t-aaron.com/live/THSAb"]
  77. # # p = sp.Popen(command, stdin=sp.PIPE)
  78. # start = time.time()
  79. # while True:
  80. #
  81. # try:
  82. # if not cap.isOpened():
  83. # cap = cv2.VideoCapture("rtmp://live.play.t-aaron.com/live/THSAf_hd")
  84. # continue
  85. # # 一帧一帧捕捉
  86. # ret, frame = cap.read() # 返回一个 bool 值(True/False)。如果加载成功,它会返回True
  87. # if not ret:
  88. # cap = cv2.VideoCapture("rtmp://live.play.t-aaron.com/live/THSAf_hd")
  89. # continue
  90. # # print(ret) #True
  91. # # # 我们对帧的操作在这里
  92. # # gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  93. # end = time.time()
  94. # print("bbbbbbbbb")
  95. # # p.stdin.write(frame.tostring())
  96. # # print("aaaaa")
  97. # out.write(frame)
  98. # except Exception as e:
  99. # raise e
  100. # # # 显示返回的每帧
  101. # # cv2.imshow('frame',gray)
  102. # # if cv2.waitKey(1) & 0xFF == ord('q'):
  103. # # break
  104. # # 当所有事完成,释放 VideoCapture 对象
  105. # cap.release()
  106. # out.release()
  107. # cv2.destroyAllWindows()