first commit
This commit is contained in:
137
get_position_test.py
Normal file
137
get_position_test.py
Normal file
@ -0,0 +1,137 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
# @Time : 2024/9/7 11:49
|
||||
# @Author : hjw
|
||||
# @File : get_position_test.py
|
||||
'''
|
||||
import time
|
||||
import platform
|
||||
import cv2
|
||||
import os
|
||||
|
||||
from Vision.camera_coordinate_dete import Detection
|
||||
from Vision.camera_coordinate_dete_planevison import Detection_plane_vsion
|
||||
from Trace.handeye_calibration import *
|
||||
from Vision.tool.utils import get_disk_space
|
||||
from Vision.tool.utils import remove_nan_mean_value
|
||||
from Vision.detect_person import DetectionPerson
|
||||
from Vision.detect_bag_num import DetectionBagNum
|
||||
from Vision.tool.CameraHIK import camera_HIK
|
||||
from Vision.bag_collection import DetectionBag
|
||||
|
||||
#
|
||||
"""
|
||||
测试 Vision
|
||||
"""
|
||||
|
||||
def detectionPosition_test():
|
||||
detection = Detection()
|
||||
while True:
|
||||
ret, img, xyz, nx_ny_nz, box = detection.get_position(Point_isVision=True, save_img_point=1)
|
||||
if ret==1:
|
||||
print('xyz点云坐标:', xyz)
|
||||
print('nx_ny_nz法向量:', nx_ny_nz)
|
||||
print('矩形框四顶点:', box)
|
||||
# img = cv2.resize(img,(720, 540))
|
||||
if xyz!=None:
|
||||
transformation_matrix = R_matrix(521.534, 0.705, 850.03, 0.0, 90.0, 0.0) # (x, y, z, u, v, w)
|
||||
target_position, noraml_base = getPosition(xyz[0], xyz[1], xyz[2], nx_ny_nz[0], nx_ny_nz[1], nx_ny_nz[2], transformation_matrix, box)
|
||||
print("target_position:", target_position)
|
||||
print("noraml_base", noraml_base)
|
||||
cv2.imshow('img', img)
|
||||
cv2.waitKey(0)
|
||||
|
||||
def Detection_plane_vsion_test():
|
||||
detection = Detection_plane_vsion()
|
||||
while True:
|
||||
ret, img, xyz, nx_ny_nz, box = detection.get_position(Point_isVision=True, save_img_point=1)
|
||||
if ret==1:
|
||||
print('xyz点云坐标:', xyz)
|
||||
print('nx_ny_nz法向量:', nx_ny_nz)
|
||||
print('矩形框四顶点:', box)
|
||||
# img = cv2.resize(img,(720, 540))
|
||||
if xyz!=None:
|
||||
transformation_matrix = R_matrix(521.534, 0.705, 850.03, 0.0, 90.0, 0.0) # (x, y, z, u, v, w)
|
||||
target_position, noraml_base = getPosition(xyz[0], xyz[1], xyz[2], nx_ny_nz[0], nx_ny_nz[1], nx_ny_nz[2], transformation_matrix, box)
|
||||
print("target_position:", target_position)
|
||||
print("noraml_base", noraml_base)
|
||||
cv2.imshow('img', img)
|
||||
cv2.waitKey(0)
|
||||
|
||||
def take_photo_position_test():
|
||||
detection = Detection()
|
||||
while True:
|
||||
ret, img, find_target, xyz = detection.get_take_photo_position()
|
||||
if ret==1:
|
||||
print('是否检测到目标:', find_target)
|
||||
if xyz!=None:
|
||||
print('xyz点云坐标:', xyz)
|
||||
else:
|
||||
print('目标点云无效')
|
||||
cv2.imshow('img', img)
|
||||
cv2.waitKey(1)
|
||||
|
||||
def detectionPerson_test():
|
||||
detectionPerson = DetectionPerson()
|
||||
while True:
|
||||
person, img_src = detectionPerson.get_person()
|
||||
if img_src is not None:
|
||||
cv2.imshow('detectPerson', img_src)
|
||||
cv2.waitKey(1)
|
||||
time.sleep(5)
|
||||
else:
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
|
||||
print("person", person)
|
||||
# video_path = ''.join([os.getcwd(), '/Vision/model/data/1.mp4'])
|
||||
# cam = cv2.VideoCapture(video_path)
|
||||
# while cam.isOpened():
|
||||
# ret, frame = cam.read()
|
||||
# if ret:
|
||||
# person, img = detectionPerson.get_person(frame)
|
||||
# print(person)
|
||||
# cv2.imshow('img', img)
|
||||
# cv2.waitKey(1)
|
||||
# else:
|
||||
# break
|
||||
def HIK_Camera_test():
|
||||
MY_CAMERA = camera_HIK("192.168.1.121", 554, "admin", "zlzk.123")
|
||||
while True:
|
||||
ret, frame = MY_CAMERA.get_img()
|
||||
if ret:
|
||||
img = cv2.resize(frame, (800, 600))
|
||||
cv2.imshow('img', img)
|
||||
cv2.waitKey(1)
|
||||
|
||||
def detectionBagNum_test():
|
||||
detectionBagNum = DetectionBagNum()
|
||||
video_path = ''.join([os.getcwd(), '/Vision/model/data/2.mp4'])
|
||||
cam = cv2.VideoCapture(video_path)
|
||||
while cam.isOpened():
|
||||
ret, frame = cam.read()
|
||||
if ret:
|
||||
num, img = detectionBagNum.get_BagNum(frame)
|
||||
print(num)
|
||||
cv2.imshow('img', img)
|
||||
cv2.waitKey(1)
|
||||
else:
|
||||
break
|
||||
|
||||
def bag_collection_test():
|
||||
save_bag_img_point = DetectionBag()
|
||||
# video_path = ''.join([os.getcwd(), '/Vision/model/data/2.mp4'])
|
||||
# cam = cv2.VideoCapture(video_path)
|
||||
while True:
|
||||
Bag, img_src = save_bag_img_point.detect_bag(save_img_point=2)
|
||||
if Bag:
|
||||
cv2.imshow('img', img_src)
|
||||
cv2.waitKey(1)
|
||||
else:
|
||||
break
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
Detection_plane_vsion_test()
|
||||
Reference in New Issue
Block a user