Panoramic

This commit is contained in:
Semi212 committed 2022-05-07 16:25:11 +08:00
1 parent a0818377bb
commit 897af7ce56
117 files changed
+79 -124

No files matched your search

Generated Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
+7 -4
View File
@@ -57,10 +57,12 @@ class DetFineVid():
if frame.shape[1] == 3840:
gp.fontScale = 3
elif frame.shape[1] == 2560:
gp.fontScale = 2
gp.fontScale = 1
else:
gp.fontScale = 1
for i in range(20):
res, frame = cap.read()
print("skip{}".format(i))
num_image = 0
while True:
@@ -129,6 +131,7 @@ class DetFineVid():
def commanddeal():
SavePath = "/data1/Hatcher/model/project/data_MPKFNet/result/"
print("starting ",gp.VideoPath)
DFS = DetFineVid(gp.VideoPath,SavePath)
DFS.StartRec()
DFS.conVideo()
@@ -261,8 +264,8 @@ def globalInit(): #deal all file in a folder
if __name__ == '__main__':
multiprocessing.set_start_method("spawn")
rootPath = "/data/DataManagement/Project/005_kunmingdianchi/0002_20220412_800_200/研究院-鱼视频/"
filedeal(rootPath)
#commanddeal()
#filedeal(rootPath)
commanddeal()
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
+1 -1
View File
@@ -1429,7 +1429,7 @@ class RealDeal():
tprint4 = time.time()
if gp.DebugPrint_flag:
print("tprint3 is ", (tprint4 - tprint3) * 1000)
draw = plot_one_box(xyxy, draw, height_or,width_or,label=label, Index=index,color=colors, line_thickness=int(3*gp.radioShowtext))
draw = plot_one_box(xyxy, draw, height_or,width_or,label=label, Index=index,color=colors, line_thickness=int(1.5*gp.radioShowtext))
tpChin1 = time.time()
if num_image > gp.showThresh :
gp.num_count_old = len(boxes_fine)
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.

Before

Width:  |  Height:  |  Size: 168 KiB

After

Width:  |  Height:  |  Size: 168 KiB

Regular → Executable
View File
File mode changed.

Before

Width:  |  Height:  |  Size: 165 KiB

After

Width:  |  Height:  |  Size: 165 KiB

View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
+11 -9
View File
@@ -8,9 +8,9 @@ import os,torch, threading,argparse
class global_para():
#check()
parser1 = argparse.ArgumentParser(description="CUI")
parser1.add_argument("--video_num", default='/data1/Hatcher/model/project/data_MPKFNet/rawdata/PYH-DEMO.mp4', type=str,
parser1.add_argument("video_num", default='/data1/Hatcher/model/project/data_MPKFNet/rawdata/竹林嘴-3月3日候鸟视频.mp4', type=str,
help='Video name.')
parser1.add_argument("--GPU", default='6', type=str,
parser1.add_argument("GPU", default='2', type=str,
help='GPU.')
parser1.add_argument("--thresh", default=0.4, type=float,
help='GPU.')
@@ -79,13 +79,13 @@ class global_para():
Fine_thresh = 0.4
# DetWeight = "/data1/Hatcher/model/Detection/yolov5/runs/train/exp21/weights/best.pt"
# FineWeight = "/data/Hatcher/data/weigth/areaproject/resnet50-PYH-3-20.7/_42522_PYH-3/best.pth"
# FineWeight = "/data/Hatcher/data/weigth/areaproject/resnet50-JXPYH-Bird-3-4-20220429/_42911_PYH-3/best.pth"
DetWeight = "/data1/Hatcher/model/Detection/yolov5/runs/train/KunMingCuiHu-Fish2/weights/best.pt"
FineWeight = "/data/Hatcher/data/weigth/areaproject/resnet50-DianChiFish-3-3-0.7/_4289_DianChiFish-4/best.pth"
FineWeight = "/data/Hatcher/data/weigth/areaproject/resnet50-KMDC-Fish-5-1-20220505/_5510_DianChiFish-4/best.pth"
# DetWeight = "/data1/Hatcher/model/Detection/yolov5/runs/train/BeijingCuiHu-Bird26/weights/best.pt"
# FineWeight = "/data/Hatcher/data/weigth/areaproject/resnet50-cui90_1model0.7/_42111_CUI-94-1/best.pth"
# BHG_chineseName = ["kong", '白鹤', '白头鹤','白枕鹤']#["kong","鲫鱼","麦穗鱼","鳑鲏"]
BHG_chineseName = ["kong","鲫鱼","麦穗鱼","鳑鲏"]
#BHG_chineseName = ["kong", '白鹤', '白头鹤','白枕鹤']
BHG_chineseName = ["kong","鲫鱼","麦穗鱼","鳑鲏","鲈鱼"]
# BHG_chineseName = ['Kong', '白额雁', '白骨顶', '苍鹭', '苍鹭', '白秋沙鸭', '白腰草鹬', '斑头雁', '斑嘴鸭', '苍鹭', '赤膀鸭', '赤颈鸭', '苍鹭', '大麻鳽',
# '豆雁', '反嘴鹬', '凤头鸊鷉', '凤头麦鸡', '凤头潜鸭', '黑鹳', '黑水鸡', '红嘴鸥', '鸿雁', '灰鹤', '灰雁', '绿翅鸭', '绿头鸭', '琵嘴鸭',
@@ -96,12 +96,13 @@ class global_para():
# '白鹈鹕', '红头潜鸭', '苍鹰', '蒙古银鸥', '西方秧鸡', '赤嘴潜鸭', '阔嘴鹬', '雕鸮', '鹌鹑', '鹗', '黄苇鳽', '黑颈鹤', '小䴙䴘', '赤麻鸭']
# BHG_chineseName =["kong","绿头鸭","斑嘴鸭","灰雁","鸿雁","kong","小鷿鷈"]
spiec_number_old = [0 for i in range(len(BHG_chineseName))]
FineClassNum = 4
FineClassNum = 5
color_show = (255, 255, 255)
color_box = (255, 0, 0)
NoneLabel = "鱼" # "鹤类"
NoneLabel = "鱼"#"鹤类" # "鱼"
fine_thresh1 = 6000
fine_thresh2 = 10000
fine_thresh2 = 6000
ShowAllNumFlag = True
fontScale = 1
"""
1.change weight
@@ -113,6 +114,7 @@ class global_para():
7. change main
8. change fine_thresh2
9. GPU
10. change ShowAllNumFlag
fontScale plot file para to adjust chinese 400W ---2
200W ---1
800W ---3
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
+60 -110
View File
@@ -2,15 +2,12 @@ import xml.dom.minidom
from tqdm import tqdm
from glob import glob
import cv2
import os
from PIL import Image
import os,argparse
import numpy as np
from jpg import jpg
txt_root_path = "/data/DataManagement/Project/005_kunmingdianchi/0002_20220412_800_200/Dataset/VOC0050201"
#xml_files = glob('./temp2/*.xml')
image_T = 50
num_count = 0
root_path = "/data/DataManagement/Project/005_kunmingdianchi/0002_20220412_800_200/Dataset/VOC0050201/Annotations/"
class_name = ["Anser albifrons" ,"Fulica atra" ,"Leucogeranus leucogeranus" ,"Egretta garzetta","Platalea leucorodia" ,"Mergellus albellus" ,"Grus monacha" ,"Tringa ochropus" ,"Numenius arquata" ,"Anser indicus","Anas zonorhyncha","Ardea cinerea","Mareca strepera" ,"Mareca penelope" ,"Tadorna ferruginea","Ardea alba","Numenius madagascariensis" ,"Botaurus stellaris" ,"Ciconia boyciana" ,"Anser fabalis" ,"Recurvirostra avosetta" ,"Podiceps cristatus","Vanellus vanellus" ,"Aythya fuligula" ,"Tringa erythropus","Calidris alpina" ,"Ciconia nigra" ,"Gallinula chloropus","Porphyrio poliocephalus","Larus ridibundus" ,"Anser cygnoides" ,"Charadrius alexandrinusw" ,"Pluvialis squatarola" ,"Grus grus" ,"Anser anser" ,"Pluvialis fulva" ,"Charadrius dubius" ,"Anas crecca","Anas platyrhynchos","Spatula clypeata","Phalacrocorax carbo","Mergus merganser" ,"Tadorna tadorna" ,"Tringa nebulariaw","Bucephala clangula" ,"Gallinago gallinago" ,"Anser erythropus","Cygnus columbianus" ,"Ichthyaetus ichthyaetus","Anas acuta" ,"Ardea intermedia"]
def cv2_crop(im, box):
'''cv2实现类似PIL的裁剪
@@ -32,111 +29,64 @@ def convert(size, box):
h = h*dh
return (x,y,w,h)
# for xml_path in os.listdir(root_path):
# xml_files = glob(os.path.join(root_path,xml_path,"*.xml"))
# print(os.path.join(root_path.replace("xml","image"),xml_path))
# jpg(os.path.join(root_path.replace("xml","image"),xml_path))
# f = open("./Hatcher_ALL.txt", "a")
# txt_lists = []
# for xml_file in tqdm(xml_files):
#
# print(xml_file+" is doing")
# DOMTree = xml.dom.minidom.parse(xml_file)
# collection = DOMTree.documentElement
# #img_name = collection.getElementsByTagName("filename")[0].childNodes[0].data
# img_name = xml_file.replace("\\xml\\","\\image\\").replace(".xml",".jpg")
# objects = collection.getElementsByTagName("object")
# #img = cv2.imread(img_name)
# img = cv2.imdecode(np.fromfile(img_name,dtype=np.uint8),-1)
# #cv2.imwrite(img_name,img)
# #img = cv2.imdecode(np.fromfile(img_name,dtype=np.uint8),-1)
# # im = Image.open(img_name)
# # im.save(img_name, quality=100)
# # im = Image.open(img_name)
# for object_id in objects:
# xmin = object_id.getElementsByTagName('bndbox')[0].getElementsByTagName('xmin')[0].childNodes[0].data
# ymin = object_id.getElementsByTagName('bndbox')[0].getElementsByTagName('ymin')[0].childNodes[0].data
# xmax = object_id.getElementsByTagName('bndbox')[0].getElementsByTagName('xmax')[0].childNodes[0].data
# ymax = object_id.getElementsByTagName('bndbox')[0].getElementsByTagName('ymax')[0].childNodes[0].data
# name = object_id.getElementsByTagName('name')[0].childNodes[0].data
# xmin = int(xmin)
# xmax = int(xmax)
# ymin = int(ymin)
# ymax = int(ymax)
# class_index = class_name.index(str(name).replace("\t","").strip())
# img1 = cv2_crop(img,(xmin, ymin,xmax, ymax))
# cv2.imwrite("H:\\Fine-grained-identification\\2021.3.25\Hatcher_One\\" + str(name).replace("\t","").strip().replace(" ","_" )+"_{}.jpg".format(num_count), img1)
# txt_lists.append(str(name).replace("\t","").strip().replace(" ","_" )+"_{}.jpg".format(num_count)+" "+str(class_index)+'\n')
# #f.write(str(name).replace("\t","").strip().replace(" ","_" )+"_{}.jpg".format(num_count)+" "+str(class_index)+'\n')
# num_count += 1
# for txt_list in txt_lists:
# f.write(txt_list)
# f.close()
# f_num = open("./num.txt", "w")
# f_num.write(str(num_count))
# f_num.close()
# print(num_count)
# for xml_file in tqdm(xml_files):
# os.remove(xml_file)
#
# #os.remove(xml_file)
# print(num_count)
def VocToFineWithLabel(num_count,root_path,image_T):
xml_files = glob(os.path.join(root_path,"*.xml"))
jpg(os.path.join(root_path.replace("Annotations","JPEGImages")))
txt_lists = []
for xml_file in tqdm(xml_files):
xml_files = glob(os.path.join(root_path,"*.xml"))
#print(os.path.join(root_path.replace("Annotations","JPEGImages")))
jpg(os.path.join(root_path.replace("Annotations","JPEGImages")))
f = open(txt_root_path+"/Hatcher_ALL.txt", "a")
txt_lists = []
for xml_file in tqdm(xml_files):
#print(xml_file+" is doing")
DOMTree = xml.dom.minidom.parse(xml_file)
collection = DOMTree.documentElement
#img_name = collection.getElementsByTagName("filename")[0].childNodes[0].data
img_name = xml_file.replace("Annotations","JPEGImages").replace(".xml",".jpg")
objects = collection.getElementsByTagName("object")
#img = cv2.imread(img_name)
img = cv2.imdecode(np.fromfile(img_name,dtype=np.uint8),-1)
#cv2.imwrite(img_name,img)
#img = cv2.imdecode(np.fromfile(img_name,dtype=np.uint8),-1)
# im = Image.open(img_name)
# im.save(img_name, quality=100)
# im = Image.open(img_name)
for object_id in objects:
xmin = object_id.getElementsByTagName('bndbox')[0].getElementsByTagName('xmin')[0].childNodes[0].data
ymin = object_id.getElementsByTagName('bndbox')[0].getElementsByTagName('ymin')[0].childNodes[0].data
xmax = object_id.getElementsByTagName('bndbox')[0].getElementsByTagName('xmax')[0].childNodes[0].data
ymax = object_id.getElementsByTagName('bndbox')[0].getElementsByTagName('ymax')[0].childNodes[0].data
name = object_id.getElementsByTagName('name')[0].childNodes[0].data
ratio_x = (3840.0/3840.0)
ratio_y = (2160.0/2160.0)
#print(ratio_x," ",ratio_y)
#print(type(xmin))
#exit()
xmin = int(float(xmin)*ratio_x)
xmax = int(float(xmax)*ratio_x)
ymin = int(float(ymin)*ratio_y)
ymax = int(float(ymax)*ratio_y)
if ((xmax - xmin)<image_T) | ((ymax - ymin)<image_T):
continue
img1 = cv2_crop(img,(xmin, ymin,xmax, ymax))
if not os.path.exists(os.path.join(root_path.replace("Annotations","FineDataset_{}".format(str(image_T))),str(name).replace("\t","").strip())):
os.makedirs(os.path.join(root_path.replace("Annotations","FineDataset_{}".format(str(image_T))),str(name).replace("\t","").strip()))
cv2.imwrite(os.path.join(root_path.replace("Annotations","FineDataset_{}".format(str(image_T))),str(name).replace("\t","").strip(),"{}.jpg".format(str(num_count).zfill(5))), img1)
#txt_lists.append(str(name).replace("\t","").strip()+"{}.jpg".format(str(num_count).zfill(5))+" "+str(class_index)+'\n')
#f.write(str(name).replace("\t","").strip().replace(" ","_" )+"_{}.jpg".format(num_count)+" "+str(class_index)+'\n')
num_count += 1
print(num_count)
# for xml_file in tqdm(xml_files):
# os.remove(xml_file)
#print(xml_file+" is doing")
DOMTree = xml.dom.minidom.parse(xml_file)
collection = DOMTree.documentElement
#img_name = collection.getElementsByTagName("filename")[0].childNodes[0].data
img_name = xml_file.replace("Annotations","JPEGImages").replace(".xml",".jpg")
objects = collection.getElementsByTagName("object")
#img = cv2.imread(img_name)
img = cv2.imdecode(np.fromfile(img_name,dtype=np.uint8),-1)
#cv2.imwrite(img_name,img)
#img = cv2.imdecode(np.fromfile(img_name,dtype=np.uint8),-1)
# im = Image.open(img_name)
# im.save(img_name, quality=100)
# im = Image.open(img_name)
for object_id in objects:
xmin = object_id.getElementsByTagName('bndbox')[0].getElementsByTagName('xmin')[0].childNodes[0].data
ymin = object_id.getElementsByTagName('bndbox')[0].getElementsByTagName('ymin')[0].childNodes[0].data
xmax = object_id.getElementsByTagName('bndbox')[0].getElementsByTagName('xmax')[0].childNodes[0].data
ymax = object_id.getElementsByTagName('bndbox')[0].getElementsByTagName('ymax')[0].childNodes[0].data
name = object_id.getElementsByTagName('name')[0].childNodes[0].data
ratio_x = (3840.0/3840.0)
ratio_y = (2160.0/2160.0)
#print(ratio_x," ",ratio_y)
#print(type(xmin))
#exit()
xmin = int(float(xmin)*ratio_x)
xmax = int(float(xmax)*ratio_x)
ymin = int(float(ymin)*ratio_y)
ymax = int(float(ymax)*ratio_y)
if ((xmax - xmin)<image_T) | ((ymax - ymin)<image_T):
continue
#class_index = class_name.index(str(name).replace("\t","").strip())
img1 = cv2_crop(img,(xmin, ymin,xmax, ymax))
if not os.path.exists(os.path.join(root_path.replace("Annotations","FineDataset_{}".format(str(image_T))),str(name).replace("\t","").strip())):
os.makedirs(os.path.join(root_path.replace("Annotations","FineDataset_{}".format(str(image_T))),str(name).replace("\t","").strip()))
cv2.imwrite(os.path.join(root_path.replace("Annotations","FineDataset_{}".format(str(image_T))),str(name).replace("\t","").strip(),"{}.jpg".format(str(num_count).zfill(5))), img1)
#txt_lists.append(str(name).replace("\t","").strip()+"{}.jpg".format(str(num_count).zfill(5))+" "+str(class_index)+'\n')
#f.write(str(name).replace("\t","").strip().replace(" ","_" )+"_{}.jpg".format(num_count)+" "+str(class_index)+'\n')
num_count += 1
for txt_list in txt_lists:
f.write(txt_list)
f.close()
f_num = open("./num.txt", "w")
f_num.write(str(num_count))
f_num.close()
print(num_count)
# for xml_file in tqdm(xml_files):
# os.remove(xml_file)
#os.remove(xml_file)
print(num_count)
if __name__ == '__main__':
print("Starting dealing......")
parser1 = argparse.ArgumentParser(description="GYD")
parser1.add_argument("image_T", default='0001', type=str,
help='Video name.')
parser1.add_argument("root_path", default='5', type=str,
help='GPU.')
args = parser1.parse_args()
num_count = 0
VocToFineWithLabel(num_count,args.root_path, int(args.image_T))
#os.remove(xml_file)
print(num_count)
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 62 KiB

Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
View File
File mode changed.
View File
File mode changed.
Loaded 100 of 117 files, more files were not shown because too many files have changed in this diff. Show more