StackBots/utils/img_cap.py

67 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import cv2
import time
cap = cv2.VideoCapture(1)
cap.set(6,cv2.VideoWriter.fourcc('M','J','P','G'))
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
ret, frame = cap.read()
cv2.imwrite(str(time.time()) + '.jpg', frame)
# def SetPoints(windowname, img):
# """
# 输入图片,打开该图片进行标记点,返回的是标记的几个点的字符串
# """
# print('(提示单击需要标记的坐标Enter确定Esc跳过其它重试。)')
# points = []
# def onMouse(event, x, y, flags, param):
# if event == cv2.EVENT_LBUTTONDOWN:
# cv2.circle(temp_img, (x, y), 10, (102, 217, 239), -1)
# points.append([x, y])
# cv2.imshow(windowname, temp_img)
# temp_img = img.copy()
# cv2.namedWindow(windowname)
# cv2.imshow(windowname, temp_img)
# cv2.setMouseCallback(windowname, onMouse)
# key = cv2.waitKey(0)
# if key == 13: # Enter
# print('坐标为:', points)
# del temp_img
# cv2.destroyAllWindows()
# return str(points)
# elif key == 27: # ESC
# print('跳过该张图片')
# del temp_img
# cv2.destroyAllWindows()
# return
# else:
# print('重试!')
# return SetPoints(windowname, img)
# SetPoints('test', frame)
# import json
# import requests
# # Run inference on an image
# url = "https://api.ultralytics.com/v1/predict/MAyxSmPez5SZXdyspDvF"
# headers = {"x-api-key": "803cf64a0603764f0657e33bb0103f8a11ffc59567"}
# data = {"size": 640, "confidence": 0.25, "iou": 0.45}
# with open("test.jpg", "rb") as f:
# response = requests.post(url, headers=headers, data=data, files={"image": f})
# # Check for successful response
# response.raise_for_status()
# # Print inference results
# print(json.dumps(response.json(), indent=2))