feat: 切换后端至PaddleOCR-NCNN,切换工程为CMake
1.项目后端整体迁移至PaddleOCR-NCNN算法,已通过基本的兼容性测试 2.工程改为使用CMake组织,后续为了更好地兼容第三方库,不再提供QMake工程 3.重整权利声明文件,重整代码工程,确保最小化侵权风险 Log: 切换后端至PaddleOCR-NCNN,切换工程为CMake Change-Id: I4d5d2c5d37505a4a24b389b1a4c5d12f17bfa38c
This commit is contained in:
38
3rdparty/ncnn/python/examples/fasterrcnn.py
vendored
Normal file
38
3rdparty/ncnn/python/examples/fasterrcnn.py
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model
|
||||
from ncnn.utils import draw_detection_objects
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s [imagepath]\n" % (sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
imagepath = sys.argv[1]
|
||||
|
||||
m = cv2.imread(imagepath)
|
||||
if m is None:
|
||||
print("cv2.imread %s failed\n" % (imagepath))
|
||||
sys.exit(0)
|
||||
|
||||
net = get_model("faster_rcnn", num_threads=4, use_gpu=True)
|
||||
|
||||
objects = net(m)
|
||||
|
||||
draw_detection_objects(m, net.class_names, objects)
|
38
3rdparty/ncnn/python/examples/mobilenetssd.py
vendored
Normal file
38
3rdparty/ncnn/python/examples/mobilenetssd.py
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model
|
||||
from ncnn.utils import draw_detection_objects
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s [imagepath]\n" % (sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
imagepath = sys.argv[1]
|
||||
|
||||
m = cv2.imread(imagepath)
|
||||
if m is None:
|
||||
print("cv2.imread %s failed\n" % (imagepath))
|
||||
sys.exit(0)
|
||||
|
||||
net = get_model("mobilenet_ssd", num_threads=4, use_gpu=True)
|
||||
|
||||
objects = net(m)
|
||||
|
||||
draw_detection_objects(m, net.class_names, objects)
|
38
3rdparty/ncnn/python/examples/mobilenetv2ssdlite.py
vendored
Normal file
38
3rdparty/ncnn/python/examples/mobilenetv2ssdlite.py
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model
|
||||
from ncnn.utils import draw_detection_objects
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s [imagepath]\n" % (sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
imagepath = sys.argv[1]
|
||||
|
||||
m = cv2.imread(imagepath)
|
||||
if m is None:
|
||||
print("cv2.imread %s failed\n" % (imagepath))
|
||||
sys.exit(0)
|
||||
|
||||
net = get_model("mobilenetv2_ssdlite", num_threads=4, use_gpu=True)
|
||||
|
||||
objects = net(m)
|
||||
|
||||
draw_detection_objects(m, net.class_names, objects)
|
38
3rdparty/ncnn/python/examples/mobilenetv3ssdlite.py
vendored
Normal file
38
3rdparty/ncnn/python/examples/mobilenetv3ssdlite.py
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model
|
||||
from ncnn.utils import draw_detection_objects
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s [imagepath]\n" % (sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
imagepath = sys.argv[1]
|
||||
|
||||
m = cv2.imread(imagepath)
|
||||
if m is None:
|
||||
print("cv2.imread %s failed\n" % (imagepath))
|
||||
sys.exit(0)
|
||||
|
||||
net = get_model("mobilenetv3_ssdlite", num_threads=4, use_gpu=True)
|
||||
|
||||
objects = net(m)
|
||||
|
||||
draw_detection_objects(m, net.class_names, objects, 0.6)
|
22
3rdparty/ncnn/python/examples/model_zoo.py
vendored
Normal file
22
3rdparty/ncnn/python/examples/model_zoo.py
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model_list
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(get_model_list())
|
46
3rdparty/ncnn/python/examples/nanodet.py
vendored
Normal file
46
3rdparty/ncnn/python/examples/nanodet.py
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import time
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model
|
||||
from ncnn.utils import draw_detection_objects
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s [imagepath]\n" % (sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
imagepath = sys.argv[1]
|
||||
|
||||
m = cv2.imread(imagepath)
|
||||
if m is None:
|
||||
print("cv2.imread %s failed\n" % (imagepath))
|
||||
sys.exit(0)
|
||||
|
||||
net = get_model(
|
||||
"nanodet",
|
||||
target_size=320,
|
||||
prob_threshold=0.4,
|
||||
nms_threshold=0.5,
|
||||
num_threads=4,
|
||||
use_gpu=True,
|
||||
)
|
||||
|
||||
objects = net(m)
|
||||
|
||||
draw_detection_objects(m, net.class_names, objects)
|
121
3rdparty/ncnn/python/examples/peleenetssd.py
vendored
Normal file
121
3rdparty/ncnn/python/examples/peleenetssd.py
vendored
Normal file
@ -0,0 +1,121 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model
|
||||
|
||||
|
||||
def draw_detection_objects_seg(image, class_names, objects, mat_map):
|
||||
color = [128, 255, 128, 244, 35, 232]
|
||||
color_count = len(color)
|
||||
|
||||
for obj in objects:
|
||||
print(
|
||||
"%d = %.5f at %.2f %.2f %.2f x %.2f\n"
|
||||
% (obj.label, obj.prob, obj.rect.x, obj.rect.y, obj.rect.w, obj.rect.h)
|
||||
)
|
||||
|
||||
cv2.rectangle(
|
||||
image,
|
||||
(int(obj.rect.x), int(obj.rect.y)),
|
||||
(int(obj.rect.x + obj.rect.w), int(obj.rect.y + obj.rect.h)),
|
||||
(255, 0, 0),
|
||||
)
|
||||
|
||||
text = "%s %.1f%%" % (class_names[int(obj.label)], obj.prob * 100)
|
||||
|
||||
label_size, baseLine = cv2.getTextSize(text, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 1)
|
||||
|
||||
x = obj.rect.x
|
||||
y = obj.rect.y - label_size[1] - baseLine
|
||||
if y < 0:
|
||||
y = 0
|
||||
if x + label_size[0] > image.shape[1]:
|
||||
x = image.shape[1] - label_size[0]
|
||||
|
||||
cv2.rectangle(
|
||||
image,
|
||||
(int(x), int(y)),
|
||||
(int(x + label_size[0]), int(y + label_size[1] + baseLine)),
|
||||
(255, 255, 255),
|
||||
-1,
|
||||
)
|
||||
|
||||
cv2.putText(
|
||||
image,
|
||||
text,
|
||||
(int(x), int(y + label_size[1])),
|
||||
cv2.FONT_HERSHEY_SIMPLEX,
|
||||
0.5,
|
||||
(0, 0, 0),
|
||||
)
|
||||
|
||||
width = mat_map.w
|
||||
height = mat_map.h
|
||||
size = mat_map.c
|
||||
img_index2 = 0
|
||||
threshold = 0.45
|
||||
ptr2 = np.array(mat_map)
|
||||
for i in range(height):
|
||||
ptr1 = image[i].flatten()
|
||||
img_index1 = 0
|
||||
for j in range(width):
|
||||
maxima = threshold
|
||||
index = -1
|
||||
for c in range(size):
|
||||
# const float* ptr3 = ptr2 + c*width*height
|
||||
ptr3 = ptr2[c].flatten()
|
||||
if ptr3[img_index2] > maxima:
|
||||
maxima = ptr3[img_index2]
|
||||
index = c
|
||||
|
||||
if index > -1:
|
||||
color_index = (index) * 3
|
||||
if color_index < color_count:
|
||||
b = color[color_index]
|
||||
g = color[color_index + 1]
|
||||
r = color[color_index + 2]
|
||||
ptr1[img_index1] = b / 2 + ptr1[img_index1] / 2
|
||||
ptr1[img_index1 + 1] = g / 2 + ptr1[img_index1 + 1] / 2
|
||||
ptr1[img_index1 + 2] = r / 2 + ptr1[img_index1 + 2] / 2
|
||||
|
||||
img_index1 += 3
|
||||
img_index2 += 1
|
||||
|
||||
image[i] = ptr1.reshape(image[i].shape)
|
||||
|
||||
cv2.imshow("image", image)
|
||||
cv2.waitKey(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s [imagepath]\n" % (sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
imagepath = sys.argv[1]
|
||||
|
||||
m = cv2.imread(imagepath)
|
||||
if m is None:
|
||||
print("cv2.imread %s failed\n" % (imagepath))
|
||||
sys.exit(0)
|
||||
|
||||
net = get_model("peleenet_ssd", num_threads=4, use_gpu=True)
|
||||
|
||||
objects, seg_out = net(m)
|
||||
|
||||
draw_detection_objects_seg(m, net.class_names, objects, seg_out)
|
38
3rdparty/ncnn/python/examples/retinaface.py
vendored
Normal file
38
3rdparty/ncnn/python/examples/retinaface.py
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model
|
||||
from ncnn.utils import draw_faceobjects
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s [imagepath]\n" % (sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
imagepath = sys.argv[1]
|
||||
|
||||
m = cv2.imread(imagepath)
|
||||
if m is None:
|
||||
print("cv2.imread %s failed\n" % (imagepath))
|
||||
sys.exit(0)
|
||||
|
||||
net = get_model("retinaface", num_threads=4, use_gpu=True)
|
||||
|
||||
faceobjects = net(m)
|
||||
|
||||
draw_faceobjects(m, faceobjects)
|
38
3rdparty/ncnn/python/examples/rfcn.py
vendored
Normal file
38
3rdparty/ncnn/python/examples/rfcn.py
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model
|
||||
from ncnn.utils import draw_detection_objects
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s [imagepath]\n" % (sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
imagepath = sys.argv[1]
|
||||
|
||||
m = cv2.imread(imagepath)
|
||||
if m is None:
|
||||
print("cv2.imread %s failed\n" % (imagepath))
|
||||
sys.exit(0)
|
||||
|
||||
net = get_model("rfcn", num_threads=4, use_gpu=True)
|
||||
|
||||
objects = net(m)
|
||||
|
||||
draw_detection_objects(m, net.class_names, objects)
|
38
3rdparty/ncnn/python/examples/shufflenetv2.py
vendored
Normal file
38
3rdparty/ncnn/python/examples/shufflenetv2.py
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model
|
||||
from ncnn.utils import print_topk
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s [imagepath]\n" % (sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
imagepath = sys.argv[1]
|
||||
|
||||
m = cv2.imread(imagepath)
|
||||
if m is None:
|
||||
print("cv2.imread %s failed\n" % (imagepath))
|
||||
sys.exit(0)
|
||||
|
||||
net = get_model("shufflenetv2", num_threads=4, use_gpu=True)
|
||||
|
||||
cls_scores = net(m)
|
||||
|
||||
print_topk(cls_scores, 3)
|
38
3rdparty/ncnn/python/examples/simplepose.py
vendored
Normal file
38
3rdparty/ncnn/python/examples/simplepose.py
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model
|
||||
from ncnn.utils import draw_pose
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s [imagepath]\n" % (sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
imagepath = sys.argv[1]
|
||||
|
||||
m = cv2.imread(imagepath)
|
||||
if m is None:
|
||||
print("cv2.imread %s failed\n" % (imagepath))
|
||||
sys.exit(0)
|
||||
|
||||
net = get_model("simplepose", num_threads=4, use_gpu=True)
|
||||
|
||||
keypoints = net(m)
|
||||
|
||||
draw_pose(m, keypoints)
|
38
3rdparty/ncnn/python/examples/squeezenet.py
vendored
Normal file
38
3rdparty/ncnn/python/examples/squeezenet.py
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model
|
||||
from ncnn.utils import print_topk
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s [imagepath]\n" % (sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
imagepath = sys.argv[1]
|
||||
|
||||
m = cv2.imread(imagepath)
|
||||
if m is None:
|
||||
print("cv2.imread %s failed\n" % (imagepath))
|
||||
sys.exit(0)
|
||||
|
||||
net = get_model("squeezenet", num_threads=4, use_gpu=True)
|
||||
|
||||
cls_scores = net(m)
|
||||
|
||||
print_topk(cls_scores, 5)
|
38
3rdparty/ncnn/python/examples/squeezenetssd.py
vendored
Normal file
38
3rdparty/ncnn/python/examples/squeezenetssd.py
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model
|
||||
from ncnn.utils import draw_detection_objects
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s [imagepath]\n" % (sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
imagepath = sys.argv[1]
|
||||
|
||||
m = cv2.imread(imagepath)
|
||||
if m is None:
|
||||
print("cv2.imread %s failed\n" % (imagepath))
|
||||
sys.exit(0)
|
||||
|
||||
net = get_model("squeezenet_ssd", num_threads=4, use_gpu=True)
|
||||
|
||||
objects = net(m)
|
||||
|
||||
draw_detection_objects(m, net.class_names, objects)
|
184
3rdparty/ncnn/python/examples/yolact.py
vendored
Normal file
184
3rdparty/ncnn/python/examples/yolact.py
vendored
Normal file
@ -0,0 +1,184 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model
|
||||
from ncnn.utils import draw_detection_objects
|
||||
|
||||
|
||||
def draw_result(image, class_names, boxes, masks, classes, scores):
|
||||
colors = [
|
||||
[56, 0, 255],
|
||||
[226, 255, 0],
|
||||
[0, 94, 255],
|
||||
[0, 37, 255],
|
||||
[0, 255, 94],
|
||||
[255, 226, 0],
|
||||
[0, 18, 255],
|
||||
[255, 151, 0],
|
||||
[170, 0, 255],
|
||||
[0, 255, 56],
|
||||
[255, 0, 75],
|
||||
[0, 75, 255],
|
||||
[0, 255, 169],
|
||||
[255, 0, 207],
|
||||
[75, 255, 0],
|
||||
[207, 0, 255],
|
||||
[37, 0, 255],
|
||||
[0, 207, 255],
|
||||
[94, 0, 255],
|
||||
[0, 255, 113],
|
||||
[255, 18, 0],
|
||||
[255, 0, 56],
|
||||
[18, 0, 255],
|
||||
[0, 255, 226],
|
||||
[170, 255, 0],
|
||||
[255, 0, 245],
|
||||
[151, 255, 0],
|
||||
[132, 255, 0],
|
||||
[75, 0, 255],
|
||||
[151, 0, 255],
|
||||
[0, 151, 255],
|
||||
[132, 0, 255],
|
||||
[0, 255, 245],
|
||||
[255, 132, 0],
|
||||
[226, 0, 255],
|
||||
[255, 37, 0],
|
||||
[207, 255, 0],
|
||||
[0, 255, 207],
|
||||
[94, 255, 0],
|
||||
[0, 226, 255],
|
||||
[56, 255, 0],
|
||||
[255, 94, 0],
|
||||
[255, 113, 0],
|
||||
[0, 132, 255],
|
||||
[255, 0, 132],
|
||||
[255, 170, 0],
|
||||
[255, 0, 188],
|
||||
[113, 255, 0],
|
||||
[245, 0, 255],
|
||||
[113, 0, 255],
|
||||
[255, 188, 0],
|
||||
[0, 113, 255],
|
||||
[255, 0, 0],
|
||||
[0, 56, 255],
|
||||
[255, 0, 113],
|
||||
[0, 255, 188],
|
||||
[255, 0, 94],
|
||||
[255, 0, 18],
|
||||
[18, 255, 0],
|
||||
[0, 255, 132],
|
||||
[0, 188, 255],
|
||||
[0, 245, 255],
|
||||
[0, 169, 255],
|
||||
[37, 255, 0],
|
||||
[255, 0, 151],
|
||||
[188, 0, 255],
|
||||
[0, 255, 37],
|
||||
[0, 255, 0],
|
||||
[255, 0, 170],
|
||||
[255, 0, 37],
|
||||
[255, 75, 0],
|
||||
[0, 0, 255],
|
||||
[255, 207, 0],
|
||||
[255, 0, 226],
|
||||
[255, 245, 0],
|
||||
[188, 255, 0],
|
||||
[0, 255, 18],
|
||||
[0, 255, 75],
|
||||
[0, 255, 151],
|
||||
[255, 56, 0],
|
||||
[245, 255, 0],
|
||||
]
|
||||
|
||||
color_index = 0
|
||||
|
||||
for box, mask, label, score in zip(boxes, masks, classes, scores):
|
||||
if score < 0.15:
|
||||
continue
|
||||
|
||||
print(
|
||||
"%s = %.5f at %.2f %.2f %.2f x %.2f\n"
|
||||
% (label, score, box[0], box[1], box[2], box[3])
|
||||
)
|
||||
|
||||
cv2.rectangle(
|
||||
image,
|
||||
(int(box[0]), int(box[1])),
|
||||
(int(box[0] + box[2]), int(int(box[1] + box[3]))),
|
||||
(255, 0, 0),
|
||||
)
|
||||
|
||||
text = "%s %.1f%%" % (class_names[int(label)], score * 100)
|
||||
|
||||
label_size, baseLine = cv2.getTextSize(text, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 1)
|
||||
|
||||
x = box[0]
|
||||
y = box[1] - label_size[1] - baseLine
|
||||
if y < 0:
|
||||
y = 0
|
||||
if x + label_size[0] > image.shape[1]:
|
||||
x = image.shape[1] - label_size[0]
|
||||
|
||||
cv2.rectangle(
|
||||
image,
|
||||
(int(x), int(y)),
|
||||
(int(x + label_size[0]), int(y + label_size[1] + baseLine)),
|
||||
(255, 255, 255),
|
||||
-1,
|
||||
)
|
||||
|
||||
cv2.putText(
|
||||
image,
|
||||
text,
|
||||
(int(x), int(y + label_size[1])),
|
||||
cv2.FONT_HERSHEY_SIMPLEX,
|
||||
0.5,
|
||||
(0, 0, 0),
|
||||
)
|
||||
|
||||
image[mask] = image[mask] * 0.5 + np.array(colors[color_index]) * 0.5
|
||||
color_index += 1
|
||||
|
||||
cv2.imshow("image", image)
|
||||
cv2.waitKey(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s [imagepath]" % (sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
imagepath = sys.argv[1]
|
||||
m = cv2.imread(imagepath)
|
||||
if m is None:
|
||||
print("cv2.imread %s failed\n" % (imagepath))
|
||||
sys.exit(0)
|
||||
|
||||
net = get_model(
|
||||
"yolact",
|
||||
target_size=550,
|
||||
confidence_threshold=0.05,
|
||||
nms_threshold=0.5,
|
||||
keep_top_k=200,
|
||||
num_threads=4,
|
||||
use_gpu=True,
|
||||
)
|
||||
|
||||
boxes, masks, classes, scores = net(m)
|
||||
|
||||
draw_result(m, net.class_names, boxes, masks, classes, scores)
|
38
3rdparty/ncnn/python/examples/yolov2.py
vendored
Normal file
38
3rdparty/ncnn/python/examples/yolov2.py
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model
|
||||
from ncnn.utils import draw_detection_objects
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s [imagepath]\n" % (sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
imagepath = sys.argv[1]
|
||||
|
||||
m = cv2.imread(imagepath)
|
||||
if m is None:
|
||||
print("cv2.imread %s failed\n" % (imagepath))
|
||||
sys.exit(0)
|
||||
|
||||
net = get_model("mobilenet_yolov2", num_threads=4, use_gpu=True)
|
||||
|
||||
objects = net(m)
|
||||
|
||||
draw_detection_objects(m, net.class_names, objects)
|
38
3rdparty/ncnn/python/examples/yolov3.py
vendored
Normal file
38
3rdparty/ncnn/python/examples/yolov3.py
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model
|
||||
from ncnn.utils import draw_detection_objects
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s [imagepath]\n" % (sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
imagepath = sys.argv[1]
|
||||
|
||||
m = cv2.imread(imagepath)
|
||||
if m is None:
|
||||
print("cv2.imread %s failed\n" % (imagepath))
|
||||
sys.exit(0)
|
||||
|
||||
net = get_model("mobilenetv2_yolov3", num_threads=4, use_gpu=True)
|
||||
|
||||
objects = net(m)
|
||||
|
||||
draw_detection_objects(m, net.class_names, objects)
|
53
3rdparty/ncnn/python/examples/yolov4.py
vendored
Normal file
53
3rdparty/ncnn/python/examples/yolov4.py
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model
|
||||
from ncnn.utils import draw_detection_objects
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s [v4l input device or image]\n" % (sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
devicepath = sys.argv[1]
|
||||
|
||||
net = get_model("yolov4_tiny", num_threads=4, use_gpu=True)
|
||||
# net = get_model("yolov4", num_threads=4, use_gpu=True)
|
||||
|
||||
if devicepath.find("/dev/video") == -1:
|
||||
m = cv2.imread(devicepath)
|
||||
if m is None:
|
||||
print("cv2.imread %s failed\n" % (devicepath))
|
||||
sys.exit(0)
|
||||
|
||||
objects = net(m)
|
||||
|
||||
draw_detection_objects(m, net.class_names, objects)
|
||||
else:
|
||||
cap = cv2.VideoCapture(devicepath)
|
||||
|
||||
if cap.isOpened() == False:
|
||||
print("Failed to open %s" % (devicepath))
|
||||
sys.exit(0)
|
||||
|
||||
while True:
|
||||
ret, frame = cap.read()
|
||||
|
||||
objects = net(frame)
|
||||
|
||||
draw_detection_objects(frame, net.class_names, objects)
|
46
3rdparty/ncnn/python/examples/yolov5.py
vendored
Normal file
46
3rdparty/ncnn/python/examples/yolov5.py
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
# Tencent is pleased to support the open source community by making ncnn available.
|
||||
#
|
||||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
#
|
||||
# Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
|
||||
# in compliance with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://opensource.org/licenses/BSD-3-Clause
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software distributed
|
||||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations under the License.
|
||||
|
||||
import sys
|
||||
import cv2
|
||||
import time
|
||||
import numpy as np
|
||||
import ncnn
|
||||
from ncnn.model_zoo import get_model
|
||||
from ncnn.utils import draw_detection_objects
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: %s [imagepath]\n" % (sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
imagepath = sys.argv[1]
|
||||
|
||||
m = cv2.imread(imagepath)
|
||||
if m is None:
|
||||
print("cv2.imread %s failed\n" % (imagepath))
|
||||
sys.exit(0)
|
||||
|
||||
net = get_model(
|
||||
"yolov5s",
|
||||
target_size=640,
|
||||
prob_threshold=0.25,
|
||||
nms_threshold=0.45,
|
||||
num_threads=4,
|
||||
use_gpu=True,
|
||||
)
|
||||
|
||||
objects = net(m)
|
||||
|
||||
draw_detection_objects(m, net.class_names, objects)
|
Reference in New Issue
Block a user