修改高拍仪方法

duizhaopin
13507605001 2 years ago
parent d52640255c
commit 8d6f6f3339

@ -57,93 +57,93 @@ class GaoPaiYi():
return {'code': -1, 'msg': e}
# win 版本
def getPic(self):
try:
p = threading.Thread(target=self.openCamera)
p.start()
time.sleep(2)
# 摄像头拍照
url = 'http://127.0.0.1:6543/video=grabimage'
# url = 'https://restapi.getui.com/v2/h8m8bkLRUG6C313Xw8sNV8/auth'
param = {
"filepath": f"{self.path}\\{str(uuid.uuid1())}.jpg",
"rotate": "90", #// 图像旋转角度90的整数倍默认"0"
"deskew": "0", #// 纠偏主头有效参数0:不纠偏1:纠偏
"deskewval":"0", #// 纠偏像素值正常给0正数时多裁负数时少裁
"camidx": "0", #// 摄像头索引参数0:主头1:副头
"ColorMode": "0", #// 色彩模式图片保存本地时调用。0彩色 1灰色 2黑白 3白纸印章 4去背景色(普通文件) 5:去背景色(身份证)
"quality": "0", #// 图片质量,图片保存本地调用
# 。0:默认质量1:高质量2:较高质量3:中质量4:较低质量5:低质量
"bAutoAdjust":"1", #// 是否自动摆正: 0不摆正 1摆正
"bIsPrint1to1":"", #// 是否1:1打印
"watermark": {
"pos": "", #// 水印在图像中的位置0:左上1:右上2:左下3:右下4:中间
"content": "", #// 水印内容必须utf-8编码当水印内容为空将当前时间作为水印
"transparency": "", #// 透明度0~255,0:完全透明255:不透明
"fontsize": "", #// 字体大小默认32
"font": "", #// 字体
"color": "" # // 水印颜色colorname
}
}
header ={'Content-Type':'application/json;charset=utf-8'}
res = requests.post(url = url,data=json.dumps(param),headers=header)
print(json.loads(res.text).get('filepath'))
if json.loads(res.text)['code'] == "0":
res_data = {'code':0,'msg':"图片保存成功","path":json.loads(res.text)['filepath'].split("\\")[-1]}
else:
res_data= {'code':-1, 'msg':"图片保存失败", "path":json.loads(res.text)['code']}
print(res_data)
# 关闭摄像头
url = 'http://127.0.0.1:6543/video=close'
param = {"camidx":"0"}
header = {'Content-Type': 'application/json;charset=utf-8'}
res = requests.post(url=url, data=json.dumps(param), headers=header,timeout=10)
print('关闭摄像头:::::::',json.loads(res.text)['code'])
stop_thread(thread=p)
return res_data
except Exception as e:
print('报错信息: ' + e + ' ,File: ' + __file__ + ', Line ' + str(sys._getframe().f_lineno))
return {'code':-1,'msg':e}
# # linux 版本
# def getPic(self):
# try:
# # if path:
# # self.path = path
# #print('----------预览视频-------------------------')
# # 打開視頻
# url = "http://localhost:6543/StartPreview?dev_idx=0&res_id=0&pixfmt=pixfmt"
# res = requests.get(url = url)
# # print(json.loads(res.text))
# #print(json.loads(res.text)['data'])
# # print(json.loads(res.text)['code']=='0')
# if json.loads(res.text)['returnCode']!=0:
# return {'code':-1,'msg':"打开视频失败"}
# p = threading.Thread(target=self.openCamera)
# p.start()
# time.sleep(2)
# # 摄像头拍照
# url = 'http://127.0.0.1:6543/video=grabimage'
# # url = 'https://restapi.getui.com/v2/h8m8bkLRUG6C313Xw8sNV8/auth'
# param = {
# "filepath": f"{self.path}\\{str(uuid.uuid1())}.jpg",
# "rotate": "90", #// 图像旋转角度90的整数倍默认"0"
# "deskew": "0", #// 纠偏主头有效参数0:不纠偏1:纠偏
# "deskewval":"0", #// 纠偏像素值正常给0正数时多裁负数时少裁
# "camidx": "0", #// 摄像头索引参数0:主头1:副头
# "ColorMode": "0", #// 色彩模式图片保存本地时调用。0彩色 1灰色 2黑白 3白纸印章 4去背景色(普通文件) 5:去背景色(身份证)
# "quality": "0", #// 图片质量,图片保存本地调用
# #print('----------拍照-------------------------',__file__)
# # 打開視頻
# url = "http://localhost:6543/getPic?savepath="+self.path+"&quality=80"
# res = requests.get(url = url)
# #print(json.loads(res.text)['data']["path"])
# #print(json.loads(res.text)['returnCode']==0) /home/yanyi/Project/MainManage/img/2022-9-9 15-36-35.jpg
# if json.loads(res.text)['returnCode']==0:
# res_data = {'code':0,'msg':"图片保存成功","path":json.loads(res.text)['data']["path"].split("/")[-1]}
# # 。0:默认质量1:高质量2:较高质量3:中质量4:较低质量5:低质量
# "bAutoAdjust":"1", #// 是否自动摆正: 0不摆正 1摆正
# "bIsPrint1to1":"", #// 是否1:1打印
# "watermark": {
# "pos": "", #// 水印在图像中的位置0:左上1:右上2:左下3:右下4:中间
# "content": "", #// 水印内容必须utf-8编码当水印内容为空将当前时间作为水印
# "transparency": "", #// 透明度0~255,0:完全透明255:不透明
# "fontsize": "", #// 字体大小默认32
# "font": "", #// 字体
# "color": "" # // 水印颜色colorname
# }
# }
# header ={'Content-Type':'application/json;charset=utf-8'}
# res = requests.post(url = url,data=json.dumps(param),headers=header)
# print(json.loads(res.text).get('filepath'))
# if json.loads(res.text)['code'] == "0":
# res_data = {'code':0,'msg':"图片保存成功","path":json.loads(res.text)['filepath'].split("\\")[-1]}
# else:
# res_data= {'code':-1, 'msg':"图片保存失败", "path":json.loads(res.text)['returnCode']}
# #print('----------关闭视频-------------------------')
# url = "http://localhost:6543/StopPreview?dev_idx=0"
# res = requests.get(url = url)
# res_data= {'code':-1, 'msg':"图片保存失败", "path":json.loads(res.text)['code']}
# print(res_data)
# # 关闭摄像头
# url = 'http://127.0.0.1:6543/video=close'
# param = {"camidx":"0"}
# header = {'Content-Type': 'application/json;charset=utf-8'}
# res = requests.post(url=url, data=json.dumps(param), headers=header,timeout=10)
# print('关闭摄像头:::::::',json.loads(res.text)['code'])
# stop_thread(thread=p)
# return res_data
# except Exception as e :
# except Exception as e:
# print('报错信息: ' + e + ' ,File: ' + __file__ + ', Line ' + str(sys._getframe().f_lineno))
# return {'code':-1,'msg':e}
# # linux 版本
def getPic(self):
try:
# if path:
# self.path = path
#print('----------预览视频-------------------------')
# 打開視頻
url = "http://localhost:6543/StartPreview?dev_idx=0&res_id=0&pixfmt=pixfmt"
res = requests.get(url = url)
# print(json.loads(res.text))
#print(json.loads(res.text)['data'])
# print(json.loads(res.text)['code']=='0')
if json.loads(res.text)['returnCode']!=0:
return {'code':-1,'msg':"打开视频失败"}
time.sleep(2)
#print('----------拍照-------------------------',__file__)
# 打開視頻
url = "http://localhost:6543/getPic?savepath="+self.path+"&quality=80"
res = requests.get(url = url)
#print(json.loads(res.text)['data']["path"])
#print(json.loads(res.text)['returnCode']==0) /home/yanyi/Project/MainManage/img/2022-9-9 15-36-35.jpg
if json.loads(res.text)['returnCode']==0:
res_data = {'code':0,'msg':"图片保存成功","path":json.loads(res.text)['data']["path"].split("/")[-1]}
else:
res_data= {'code':-1, 'msg':"图片保存失败", "path":json.loads(res.text)['returnCode']}
#print('----------关闭视频-------------------------')
url = "http://localhost:6543/StopPreview?dev_idx=0"
res = requests.get(url = url)
return res_data
except Exception as e :
print('报错信息: ' + e + ' ,File: ' + __file__ + ', Line ' + str(sys._getframe().f_lineno))
return {'code':-1,'msg':e}
if __name__ =="__main__":

Loading…
Cancel
Save