capture_basic_mode.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import time
  2. import settings
  3. from sys import platform as sys_platform
  4. from utils.utils_func import httpGetHandler
  5. from PIL import Image
  6. from io import BytesIO
  7. import requests
  8. if settings.IS_TEST:
  9. import piexif
  10. from PIL import Image
  11. import threading
  12. class CaptureBasic():
  13. # program_sign = Signal(dict)0
  14. base_host = "http://localhost:5513"
  15. _get_image_index = 0
  16. _get_folder_index = 0
  17. is_first_init = 0
  18. def __init__(self):
  19. # self.window = window
  20. # 状态 1 进行中 2 已停止
  21. self.state = 2
  22. # 总拍照数量
  23. self.total_num = 0
  24. # 是否获取照片
  25. self.is_get_photo = False
  26. # self.keyboard = Controller()
  27. self.hwnd = None
  28. def getPreviewImage(self)->Image:
  29. '''获取预览图'''
  30. yzmdata = requests.get(self.base_host + "/preview.jpg")
  31. tempIm = BytesIO(yzmdata.content)
  32. im = Image.open(tempIm)
  33. return im
  34. def getCaptureFolderPath(self) -> Image:
  35. """获取预览图"""
  36. response = httpGetHandler(
  37. url=self.base_host,
  38. params={"slc": "get", "param1": "session.folder"},
  39. headers={},
  40. )
  41. return response.text
  42. def run_capture_action(self,command):
  43. '''执行capture动作'''
  44. response = httpGetHandler(url=self.base_host, params={"CMD":command},headers={})
  45. return response
  46. # def photograph(self):
  47. # """
  48. # Args:
  49. # data:
  50. # info_show: 信息输出
  51. # image_deal_mode:0 表示左脚,1表示右脚
  52. # Returns:
  53. # """
  54. # print("142----------------------------photograph")
  55. # # 执行拍照
  56. # if not self.hwnd:
  57. # return False, {"flag": "{} 未打开".format(settings.CaptureSoftwareName)}
  58. # if self.state == 1:
  59. # print("当前有未完成的任务")
  60. # return False, {"flag": "当前有未完成的任务"}
  61. # print("开始拍照")
  62. # self.state = 1
  63. # if not self.set_foreground_window():
  64. # return False, {"flag": "no {}".format(settings.CaptureSoftwareName)}
  65. # time.sleep(0.1)
  66. # # 自动对焦
  67. # self.auto_focus()
  68. # # self.send_win32_key(self.hwnd, key_1=win32con.VK_CONTROL, key_2=win32con.VK_F2)
  69. # if settings.IS_TEST:
  70. # # print("56-----测试拍照")
  71. # threading.Thread(target=self.test_add_photo, args=()).start()
  72. # # self.program_sign.emit({"type": "add_to_photo_todo_list",
  73. # # "data": data})
  74. # time.sleep(float(settings.PhotographSeconds))
  75. # def test_add_photo(self):
  76. # def copy_file(srcfile, dstpath, dstfile): # 复制函数
  77. # if not os.path.isfile(srcfile):
  78. # # print("%s not exist!" % (srcfile))
  79. # return
  80. # else:
  81. # if int(os.path.getsize(srcfile) / 1024) < 10:
  82. # return
  83. # # fpath, fname = os.path.split(srcfile) # 分离文件名和路径
  84. # if not os.path.exists(dstpath):
  85. # os.makedirs(dstpath) # 创建路径
  86. # shutil.copy(srcfile, dstfile) # 复制文件
  87. # print("模拟拍照 test_add_photo")
  88. # time.sleep(0.9)
  89. # s = time.time()
  90. # source_path = r"{}\PhotoImageDir\test_source".format(os.getcwd())
  91. # check_path(source_path)
  92. # # 整理所有测试源照片
  93. # images_path_list = []
  94. # folder_list = get_folder(source_path)
  95. # for folder_dict in folder_list:
  96. # folder_path = folder_dict["folder_path"]
  97. # _pics = [x["file_path"] for x in get_images(folder_path)]
  98. # if _pics:
  99. # images_path_list.append(_pics)
  100. # if len(images_path_list) <= CaptureBasic._get_folder_index:
  101. # CaptureBasic._get_folder_index = 0
  102. # CaptureBasic._get_image_index = 0
  103. # srcfile = images_path_list[CaptureBasic._get_folder_index][CaptureBasic._get_image_index]
  104. # # 新文件夹
  105. # CaptureBasic._get_image_index += 1
  106. # if len(images_path_list[CaptureBasic._get_folder_index]) <= CaptureBasic._get_image_index:
  107. # CaptureBasic._get_folder_index += 1
  108. # CaptureBasic._get_image_index = 0
  109. # # print("pic:", srcfile)
  110. # e = os.path.splitext(os.path.split(srcfile)[1])[1]
  111. # # 修改图片时间
  112. # if e != ".CR2":
  113. # _time = time.strftime("%Y:%m:%d %H:%M:%S", time.localtime(time.time()))
  114. # exif_ifd = {piexif.ExifIFD.DateTimeOriginal: _time}
  115. # exif_dict = {"Exif": exif_ifd}
  116. # exif_bytes = piexif.dump(exif_dict)
  117. # im = Image.open(srcfile)
  118. # im.save(srcfile, exif=exif_bytes)
  119. # dst_path = settings.PhotoOutputDir
  120. # # dst_path = "{}/data".format(os.getcwd())
  121. # e = os.path.splitext(srcfile)[-1]
  122. # new_name = "~{}{}".format(int(time.time() * 10), e)
  123. # dst_file = "{}/{}".format(dst_path, new_name)
  124. # print("测试数据 dst_file", dst_file)
  125. # copy_file(srcfile, dst_path, dst_file)
  126. # # print("修改图片耗时:{}".format(time.time() - s))
  127. def auto_focus(self):
  128. # 执行拍照
  129. time.sleep(0.2)
  130. self.run_capture_action("LiveView_Focus")
  131. def last_images(self):
  132. if not self.hwnd:
  133. return
  134. # win32gui.SetForegroundWindow(self.hwnd)
  135. # self.keyboard.press(Key.ctrl)
  136. # self.keyboard.press(Key.left)
  137. # self.keyboard.release(Key.left)
  138. # self.keyboard.release(Key.ctrl)
  139. def next_images(self):
  140. # 执行拍照
  141. if not self.hwnd:
  142. return
  143. # win32gui.SetForegroundWindow(self.hwnd)
  144. # self.keyboard.press(Key.ctrl)
  145. # self.keyboard.press(Key.right)
  146. # self.keyboard.release(Key.right)
  147. # self.keyboard.release(Key.ctrl)
  148. def test_1(self):
  149. if not self.hwnd:
  150. return
  151. # 执行照片全选与导出
  152. # win32gui.SetForegroundWindow(self.hwnd)
  153. # self.keyboard.press(Key.ctrl)
  154. # self.keyboard.press("a")
  155. # self.keyboard.release("a")
  156. # self.keyboard.release(Key.ctrl)
  157. # time.sleep(1)
  158. # # 照片导出
  159. # self.keyboard.press(Key.ctrl)
  160. # self.keyboard.press("d")
  161. # self.keyboard.release("d")
  162. # self.keyboard.release(Key.ctrl)
  163. if __name__ == "__main__":
  164. cap = CaptureBasic()
  165. cap.auto_focus()
  166. print("cccc")