add util & example
This commit is contained in:
@@ -4,16 +4,9 @@ import cv2
|
||||
import orisys
|
||||
|
||||
def main():
|
||||
global start_time
|
||||
|
||||
box = []
|
||||
dx = 90
|
||||
dy = -95
|
||||
for i in range(15):
|
||||
box.append((410+dx, 900+dy, 620+dx, 1110+dy))
|
||||
# 打开视频
|
||||
sensor1 = orisys.Sensor("./s1.mp4",isstitch=True,cuda = True,verbose = True)
|
||||
|
||||
# 打开摄像头
|
||||
# sensor1 = Sensor(0,isstitch=True,cuda = True,verbose = True)
|
||||
|
||||
@@ -33,7 +26,6 @@ def main():
|
||||
cv2.imshow("Deformation", arrows)
|
||||
|
||||
depth_img = cv2.applyColorMap((depth*1* 255.0).astype('uint8'), cv2.COLORMAP_HOT)
|
||||
|
||||
cv2.imshow('depth', depth_img)
|
||||
|
||||
key = cv2.waitKey(1)
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import orisys
|
||||
def main():
|
||||
global start_time
|
||||
|
||||
# 打开视频
|
||||
# 打开视频, config_name 可以根据传感型号选择
|
||||
sensor1 = orisys.Sensor("./s1.mp4",isstitch=True,cuda = True,verbose = True, config_name="prototype")
|
||||
# sensor1 = Sensor(0,isstitch=True,cuda = True,verbose = True, config_name="prototype")
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import os
|
||||
os.environ["OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS"] = "0"
|
||||
import cv2
|
||||
import orisys
|
||||
|
||||
def main():
|
||||
global start_time
|
||||
|
||||
box = []
|
||||
dx = 90
|
||||
dy = -95
|
||||
for i in range(15):
|
||||
box.append((410+dx, 900+dy, 620+dx, 1110+dy))
|
||||
# 打开视频,手动设置box 的坐标
|
||||
sensor1 = orisys.Sensor("./s1.mp4",isstitch=False,cuda = True,verbose = True, override=True, box=box)
|
||||
# sensor1 = orisys.Sensor("./uv_2.mp4",isstitch=True,cuda = True,verbose = True, override=True, box=box)
|
||||
# 打开摄像头
|
||||
# sensor1 = Sensor(0,isstitch=True,cuda = True,verbose = True)
|
||||
|
||||
|
||||
while True:
|
||||
sensor1.get_img() # 提取并拼接复眼图像
|
||||
sensor1.compute_deformation() # 计算形变和分解
|
||||
# 提取信息:
|
||||
# 向量场: VRAW, VNORMAL, VSHEAR: 原始,法向,切向
|
||||
# 帧率,时间戳: FPS, TIMESTAMP
|
||||
# 变形量总和: FNORMAL , FSHEARX, FSHEARY : 法向,切向(X),切向(Y)
|
||||
# 深度图: DEPTH
|
||||
fps, fn, fx, fy, flow, depth = sensor1.read_info(sensor1.info.FPS, sensor1.info.FNORMAL, sensor1.info.FSHEARX, sensor1.info.FSHEARY, sensor1.info.VRAW, sensor1.info.DEPTH)
|
||||
print(fps,fn,fx,fy)
|
||||
# 显示向量场
|
||||
arrows = orisys.util.draw_arrows(sensor1.img, flow, threshold=5, grid_spacing=40, arrow_scale=1.0)
|
||||
cv2.imshow("Deformation", arrows)
|
||||
|
||||
depth_img = cv2.applyColorMap((depth*1* 255.0).astype('uint8'), cv2.COLORMAP_HOT)
|
||||
|
||||
cv2.imshow('depth', depth_img)
|
||||
|
||||
key = cv2.waitKey(1)
|
||||
if key & 0xFF == ord("q"):
|
||||
print("\n 停止程序")
|
||||
break
|
||||
if key & 0xFF == ord("r"):
|
||||
sensor1.reset()
|
||||
|
||||
sensor1.disconnect() # 断开传感器连接
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -5,9 +5,10 @@ A Python library for processing and analyzing optical tactile sensor data,
|
||||
including image stitching, optical flow tracking, and deformation decomposition.
|
||||
"""
|
||||
|
||||
__version__ = "0.2.0"
|
||||
__version__ = "0.1.0"
|
||||
__author__ = "Orisys"
|
||||
|
||||
from .sensor import Sensor
|
||||
from . import util
|
||||
|
||||
__all__ = ['Sensor']
|
||||
__all__ = ['Sensor', 'util']
|
||||
|
||||
+15
-17
@@ -10,7 +10,6 @@ from enum import Enum, auto
|
||||
from typing import Optional, Tuple, Union, Any
|
||||
from .getDensity import getFilteredDensity
|
||||
from . import configs
|
||||
from .util import draw_arrows, draw_magnitude_map, draw_fps
|
||||
|
||||
class Sensor:
|
||||
"""
|
||||
@@ -56,7 +55,7 @@ class Sensor:
|
||||
self.hhd = None
|
||||
|
||||
# Setup video capture
|
||||
self.__open_video_source()
|
||||
self.__open_video_source(override, box)
|
||||
|
||||
# Logging state
|
||||
self.last_log_time = time.time()
|
||||
@@ -80,7 +79,7 @@ class Sensor:
|
||||
FSHEARY = auto()
|
||||
DEPTH = auto()
|
||||
|
||||
def __open_video_source(self):
|
||||
def __open_video_source(self, override, box):
|
||||
|
||||
# Setup video capture
|
||||
self.cap = cv2.VideoCapture(self.vid_src)
|
||||
@@ -101,12 +100,19 @@ class Sensor:
|
||||
else:
|
||||
raise Exception("Failed to open video source.")
|
||||
|
||||
# Initialize stitching calibration
|
||||
self.__find_stitch_boxes(frame, show=False)
|
||||
self.__get_tiles(frame)
|
||||
self.stitch_cal()
|
||||
if self.verbose:
|
||||
print("Sensor initialized and calibrated.")
|
||||
if override:
|
||||
if box is not None:
|
||||
|
||||
self.isstitch = False
|
||||
self.__stitcher.isstitch = False
|
||||
self.__stitcher.boxes = box
|
||||
else:
|
||||
print("Override is True but no box provided.")
|
||||
else:
|
||||
# Initialize and calibrate
|
||||
self.__find_stitch_boxes(frame, show=False)
|
||||
self.__get_tiles(frame)
|
||||
self.stitch_cal()
|
||||
|
||||
def get_config(self):
|
||||
"""
|
||||
@@ -349,11 +355,3 @@ class Sensor:
|
||||
# print("Image stitched with shape:", img_stitched_height.shape)
|
||||
return img_stitched_height
|
||||
|
||||
# def draw_arrows(self, optical_flow, fps=True, threshold=5, grid_spacing=40, arrow_scale=1.0):
|
||||
# return draw_arrows(self.img, optical_flow, fps, threshold, grid_spacing, arrow_scale)
|
||||
|
||||
# def draw_magnitude_map(self, flow_field, threshold=3.0, colormap=cv2.COLORMAP_JET):
|
||||
# return draw_magnitude_map(self.img, flow_field, threshold, colormap)
|
||||
|
||||
# def draw_fps(self, fps):
|
||||
# return draw_fps(self.img, fps)
|
||||
|
||||
Reference in New Issue
Block a user