capture_basic_mode.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 auto_focus(self):
  35. # 执行拍照
  36. time.sleep(0.2)
  37. self.run_capture_action("LiveView_Focus")
  38. def getCaptureFolderPath(self):
  39. """获取预览图"""
  40. response = httpGetHandler(
  41. url=self.base_host,
  42. params={"slc": "get", "param1": "session.folder"},
  43. headers={},
  44. )
  45. return response.text
  46. def run_capture_action(self,command):
  47. '''执行capture动作'''
  48. response = httpGetHandler(url=self.base_host, params={"CMD":command},headers={})
  49. return response
  50. # def photograph(self):
  51. # """
  52. # Args:
  53. # data:
  54. # info_show: 信息输出
  55. # image_deal_mode:0 表示左脚,1表示右脚
  56. # Returns:
  57. # """
  58. # print("142----------------------------photograph")
  59. # # 执行拍照
  60. # if not self.hwnd:
  61. # return False, {"flag": "{} 未打开".format(settings.CaptureSoftwareName)}
  62. # if self.state == 1:
  63. # print("当前有未完成的任务")
  64. # return False, {"flag": "当前有未完成的任务"}
  65. # print("开始拍照")
  66. # self.state = 1
  67. # if not self.set_foreground_window():
  68. # return False, {"flag": "no {}".format(settings.CaptureSoftwareName)}
  69. # time.sleep(0.1)
  70. # # 自动对焦
  71. # self.auto_focus()
  72. # # self.send_win32_key(self.hwnd, key_1=win32con.VK_CONTROL, key_2=win32con.VK_F2)
  73. # if settings.IS_TEST:
  74. # # print("56-----测试拍照")
  75. # threading.Thread(target=self.test_add_photo, args=()).start()
  76. # # self.program_sign.emit({"type": "add_to_photo_todo_list",
  77. # # "data": data})
  78. # time.sleep(float(settings.PhotographSeconds))
  79. # def test_add_photo(self):
  80. # def copy_file(srcfile, dstpath, dstfile): # 复制函数
  81. # if not os.path.isfile(srcfile):
  82. # # print("%s not exist!" % (srcfile))
  83. # return
  84. # else:
  85. # if int(os.path.getsize(srcfile) / 1024) < 10:
  86. # return
  87. # # fpath, fname = os.path.split(srcfile) # 分离文件名和路径
  88. # if not os.path.exists(dstpath):
  89. # os.makedirs(dstpath) # 创建路径
  90. # shutil.copy(srcfile, dstfile) # 复制文件
  91. # print("模拟拍照 test_add_photo")
  92. # time.sleep(0.9)
  93. # s = time.time()
  94. # source_path = r"{}\PhotoImageDir\test_source".format(os.getcwd())
  95. # check_path(source_path)
  96. # # 整理所有测试源照片
  97. # images_path_list = []
  98. # folder_list = get_folder(source_path)
  99. # for folder_dict in folder_list:
  100. # folder_path = folder_dict["folder_path"]
  101. # _pics = [x["file_path"] for x in get_images(folder_path)]
  102. # if _pics:
  103. # images_path_list.append(_pics)
  104. # if len(images_path_list) <= CaptureBasic._get_folder_index:
  105. # CaptureBasic._get_folder_index = 0
  106. # CaptureBasic._get_image_index = 0
  107. # srcfile = images_path_list[CaptureBasic._get_folder_index][CaptureBasic._get_image_index]
  108. # # 新文件夹
  109. # CaptureBasic._get_image_index += 1
  110. # if len(images_path_list[CaptureBasic._get_folder_index]) <= CaptureBasic._get_image_index:
  111. # CaptureBasic._get_folder_index += 1
  112. # CaptureBasic._get_image_index = 0
  113. # # print("pic:", srcfile)
  114. # e = os.path.splitext(os.path.split(srcfile)[1])[1]
  115. # # 修改图片时间
  116. # if e != ".CR2":
  117. # _time = time.strftime("%Y:%m:%d %H:%M:%S", time.localtime(time.time()))
  118. # exif_ifd = {piexif.ExifIFD.DateTimeOriginal: _time}
  119. # exif_dict = {"Exif": exif_ifd}
  120. # exif_bytes = piexif.dump(exif_dict)
  121. # im = Image.open(srcfile)
  122. # im.save(srcfile, exif=exif_bytes)
  123. # dst_path = settings.PhotoOutputDir
  124. # # dst_path = "{}/data".format(os.getcwd())
  125. # e = os.path.splitext(srcfile)[-1]
  126. # new_name = "~{}{}".format(int(time.time() * 10), e)
  127. # dst_file = "{}/{}".format(dst_path, new_name)
  128. # print("测试数据 dst_file", dst_file)
  129. # copy_file(srcfile, dst_path, dst_file)
  130. # # print("修改图片耗时:{}".format(time.time() - s))
  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. cap.auto_focus()
  167. cap.run_capture_action("Capture")
  168. print("cccc")