绘制点数据()-其他
绘制点数据()
绘制点数据
import os
import matplotlib.pyplot as plt
import cv2
import math
def loadTxtData(uwb_data_file):
list_x = []
list_y = []
#txtFile = open("2.txt",'rb')
with open(uwb_data_file,'r') as fileObj:
linesStr = fileObj.readlines()
#1 9 3197 4587 2593 77 4 0 2022-03-07 10:38:56 1
#print(lineStr)
for lineStr in linesStr:
line_strs = lineStr.split("\t")
#if len(line_str)==11:
list_x.append(float(line_strs[2]))
list_y.append(float(line_strs[3]))
#print(line[2],line[3])
#list_x.append(line[2])
#list_y.append(line[3])
return list_x,list_y
def drawPoint(img,list_x,list_y,scale_x,scale_y,n_w,n_h,o_x,o_y,color_param):
for k in range(2,len(list_x)-2):
indexX0 = int(list_x[k-1]/scale_x)
indexY0 = int(list_y[k-1]/scale_y)
indexX1 = int(list_x[k]/scale_x)
indexY1 = int(list_y[k]/scale_y)
indexX2 = int(list_x[k+1]/scale_x)
indexY2 = int(list_y[k+1]/scale_y)
dis01 = math.sqrt((indexX0-indexX1)*(indexX0-indexX1) + (indexY0-indexY1)*(indexY0-indexY1))
dis12 = math.sqrt((indexX1-indexX2)*(indexX1-indexX2) + (indexY1-indexY2)*(indexY1-indexY2))
if dis01>100 or dis12>100:
continue
if indexX1==0 and indexY1==0:
continue
indexX = indexX1 - o_x
indexY = o_y + indexY1*(-1) + 500
#circleIn = cv2.circle(img,center = (width // 2, height // 2) , radius = int(min(height, width) / 3) , color = 0, thickness = -1)
cv2.circle(img,center=(indexX,indexY),radius=6,color=color_param,thickness=6)
img2 = cv2.resize(img,(n_w,n_h))
cv2.imshow("win",img2)
cv2.waitKey(20)
def drawUWB():
list_x,list_y = loadTxtData(uwb_data_file="10.txt")
list_x1,list_y1 = loadTxtData(uwb_data_file="1.txt")
print(list_y)
#plt.plot(list_x,list_y)
#plt.scatter(list_x,list_y,color = 'red')
#plt.show()
scale_x = 25.00
scale_y = 25.00
start_x = 373
start_y = 1490
o_x = 370
o_y =1500
img = cv2.imread("1.jpg")
if img.shape[0]>0:
width = img.shape[1]
height = img.shape[0]
n_w = int(width/3)
n_h = int(height/3)
cv2.circle(img,center=(o_x,o_y),radius=10,color=(0,255,0),thickness=10)
#cv2.circle(img,)
color_param = (0,0,255)
drawPoint(img,list_x,list_y,scale_x,scale_y,n_w,n_h,o_x,o_y,color_param)
color_param1 = (255,0,0)
drawPoint(img,list_x1,list_y1,scale_x,scale_y,n_w,n_h,o_x,o_y,color_param1)
#
cv2.imwrite("1_out.jpg",img)
cv2.waitKey(0)
drawUWB()
##################
————————
绘制点数据
import os
import matplotlib.pyplot as plt
import cv2
import math
def loadTxtData(uwb_data_file):
list_x = []
list_y = []
#txtFile = open("2.txt",'rb')
with open(uwb_data_file,'r') as fileObj:
linesStr = fileObj.readlines()
#1 9 3197 4587 2593 77 4 0 2022-03-07 10:38:56 1
#print(lineStr)
for lineStr in linesStr:
line_strs = lineStr.split("\t")
#if len(line_str)==11:
list_x.append(float(line_strs[2]))
list_y.append(float(line_strs[3]))
#print(line[2],line[3])
#list_x.append(line[2])
#list_y.append(line[3])
return list_x,list_y
def drawPoint(img,list_x,list_y,scale_x,scale_y,n_w,n_h,o_x,o_y,color_param):
for k in range(2,len(list_x)-2):
indexX0 = int(list_x[k-1]/scale_x)
indexY0 = int(list_y[k-1]/scale_y)
indexX1 = int(list_x[k]/scale_x)
indexY1 = int(list_y[k]/scale_y)
indexX2 = int(list_x[k+1]/scale_x)
indexY2 = int(list_y[k+1]/scale_y)
dis01 = math.sqrt((indexX0-indexX1)*(indexX0-indexX1) + (indexY0-indexY1)*(indexY0-indexY1))
dis12 = math.sqrt((indexX1-indexX2)*(indexX1-indexX2) + (indexY1-indexY2)*(indexY1-indexY2))
if dis01>100 or dis12>100:
continue
if indexX1==0 and indexY1==0:
continue
indexX = indexX1 - o_x
indexY = o_y + indexY1*(-1) + 500
#circleIn = cv2.circle(img,center = (width // 2, height // 2) , radius = int(min(height, width) / 3) , color = 0, thickness = -1)
cv2.circle(img,center=(indexX,indexY),radius=6,color=color_param,thickness=6)
img2 = cv2.resize(img,(n_w,n_h))
cv2.imshow("win",img2)
cv2.waitKey(20)
def drawUWB():
list_x,list_y = loadTxtData(uwb_data_file="10.txt")
list_x1,list_y1 = loadTxtData(uwb_data_file="1.txt")
print(list_y)
#plt.plot(list_x,list_y)
#plt.scatter(list_x,list_y,color = 'red')
#plt.show()
scale_x = 25.00
scale_y = 25.00
start_x = 373
start_y = 1490
o_x = 370
o_y =1500
img = cv2.imread("1.jpg")
if img.shape[0]>0:
width = img.shape[1]
height = img.shape[0]
n_w = int(width/3)
n_h = int(height/3)
cv2.circle(img,center=(o_x,o_y),radius=10,color=(0,255,0),thickness=10)
#cv2.circle(img,)
color_param = (0,0,255)
drawPoint(img,list_x,list_y,scale_x,scale_y,n_w,n_h,o_x,o_y,color_param)
color_param1 = (255,0,0)
drawPoint(img,list_x1,list_y1,scale_x,scale_y,n_w,n_h,o_x,o_y,color_param1)
#
cv2.imwrite("1_out.jpg",img)
cv2.waitKey(0)
drawUWB()
##################