mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Merge branch 4.x
This commit is contained in:
@@ -44,8 +44,8 @@ int main(int argc, char** argv)
|
||||
"{image2 i2 | | Path to the input image2. When image1 and image2 parameters given then the program try to find a face on both images and runs face recognition algorithm}"
|
||||
"{video v | 0 | Path to the input video}"
|
||||
"{scale sc | 1.0 | Scale factor used to resize input video frames}"
|
||||
"{fd_model fd | yunet.onnx | Path to the model. Download yunet.onnx in https://github.com/ShiqiYu/libfacedetection.train/tree/master/tasks/task1/onnx }"
|
||||
"{fr_model fr | face_recognizer_fast.onnx | Path to the face recognition model. Download the model at https://drive.google.com/file/d/1ClK9WiB492c5OZFKveF3XiHCejoOxINW/view}"
|
||||
"{fd_model fd | face_detection_yunet_2021dec.onnx| Path to the model. Download yunet.onnx in https://github.com/opencv/opencv_zoo/tree/master/models/face_detection_yunet}"
|
||||
"{fr_model fr | face_recognition_sface_2021dec.onnx | Path to the face recognition model. Download the model at https://github.com/opencv/opencv_zoo/tree/master/models/face_recognition_sface}"
|
||||
"{score_threshold | 0.9 | Filter out faces of score < score_threshold}"
|
||||
"{nms_threshold | 0.3 | Suppress bounding boxes of iou >= nms_threshold}"
|
||||
"{top_k | 5000 | Keep top_k bounding boxes before NMS}"
|
||||
@@ -65,6 +65,7 @@ int main(int argc, char** argv)
|
||||
int topK = parser.get<int>("top_k");
|
||||
|
||||
bool save = parser.get<bool>("save");
|
||||
float scale = parser.get<float>("scale");
|
||||
|
||||
double cosine_similar_thresh = 0.363;
|
||||
double l2norm_similar_thresh = 1.128;
|
||||
@@ -87,6 +88,9 @@ int main(int argc, char** argv)
|
||||
return 2;
|
||||
}
|
||||
|
||||
int imageWidth = int(image1.cols * scale);
|
||||
int imageHeight = int(image1.rows * scale);
|
||||
resize(image1, image1, Size(imageWidth, imageHeight));
|
||||
tm.start();
|
||||
|
||||
//! [inference]
|
||||
@@ -199,7 +203,6 @@ int main(int argc, char** argv)
|
||||
else
|
||||
{
|
||||
int frameWidth, frameHeight;
|
||||
float scale = parser.get<float>("scale");
|
||||
VideoCapture capture;
|
||||
std::string video = parser.get<string>("video");
|
||||
if (video.size() == 1 && isdigit(video[0]))
|
||||
|
||||
@@ -16,8 +16,8 @@ parser.add_argument('--image1', '-i1', type=str, help='Path to the input image1.
|
||||
parser.add_argument('--image2', '-i2', type=str, help='Path to the input image2. When image1 and image2 parameters given then the program try to find a face on both images and runs face recognition algorithm.')
|
||||
parser.add_argument('--video', '-v', type=str, help='Path to the input video.')
|
||||
parser.add_argument('--scale', '-sc', type=float, default=1.0, help='Scale factor used to resize input video frames.')
|
||||
parser.add_argument('--face_detection_model', '-fd', type=str, default='yunet.onnx', help='Path to the face detection model. Download the model at https://github.com/ShiqiYu/libfacedetection.train/tree/master/tasks/task1/onnx.')
|
||||
parser.add_argument('--face_recognition_model', '-fr', type=str, default='face_recognizer_fast.onnx', help='Path to the face recognition model. Download the model at https://drive.google.com/file/d/1ClK9WiB492c5OZFKveF3XiHCejoOxINW/view.')
|
||||
parser.add_argument('--face_detection_model', '-fd', type=str, default='face_detection_yunet_2021dec.onnx', help='Path to the face detection model. Download the model at https://github.com/opencv/opencv_zoo/tree/master/models/face_detection_yunet')
|
||||
parser.add_argument('--face_recognition_model', '-fr', type=str, default='face_recognition_sface_2021dec.onnx', help='Path to the face recognition model. Download the model at https://github.com/opencv/opencv_zoo/tree/master/models/face_recognition_sface')
|
||||
parser.add_argument('--score_threshold', type=float, default=0.9, help='Filtering out faces of score < score_threshold.')
|
||||
parser.add_argument('--nms_threshold', type=float, default=0.3, help='Suppress bounding boxes of iou >= nms_threshold.')
|
||||
parser.add_argument('--top_k', type=int, default=5000, help='Keep top_k bounding boxes before NMS.')
|
||||
@@ -56,11 +56,15 @@ if __name__ == '__main__':
|
||||
# If input is an image
|
||||
if args.image1 is not None:
|
||||
img1 = cv.imread(cv.samples.findFile(args.image1))
|
||||
img1Width = int(img1.shape[1]*args.scale)
|
||||
img1Height = int(img1.shape[0]*args.scale)
|
||||
|
||||
img1 = cv.resize(img1, (img1Width, img1Height))
|
||||
tm.start()
|
||||
|
||||
## [inference]
|
||||
# Set input size before inference
|
||||
detector.setInputSize((img1.shape[1], img1.shape[0]))
|
||||
detector.setInputSize((img1Width, img1Height))
|
||||
|
||||
faces1 = detector.detect(img1)
|
||||
## [inference]
|
||||
|
||||
@@ -195,7 +195,7 @@ def main():
|
||||
indices = cv.dnn.NMSBoxesRotated(boxes, confidences, confThreshold, nmsThreshold)
|
||||
for i in indices:
|
||||
# get 4 corners of the rotated rect
|
||||
vertices = cv.boxPoints(boxes[i[0]])
|
||||
vertices = cv.boxPoints(boxes[i])
|
||||
# scale the bounding box coordinates based on the respective ratios
|
||||
for j in range(4):
|
||||
vertices[j][0] *= rW
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
'''
|
||||
Plot camera calibration extrinsics.
|
||||
|
||||
usage:
|
||||
camera_calibration_show_extrinsics.py [--calibration <input path>] [--cam_width] [--cam_height] [--scale_focal] [--patternCentric ]
|
||||
|
||||
default values:
|
||||
--calibration : left_intrinsics.yml
|
||||
--cam_width : 0.064/2
|
||||
--cam_height : 0.048/2
|
||||
--scale_focal : 40
|
||||
--patternCentric : True
|
||||
'''
|
||||
|
||||
# Python 2/3 compatibility
|
||||
from __future__ import print_function
|
||||
|
||||
@@ -222,7 +222,7 @@ def mosaic(w, imgs):
|
||||
pad = np.zeros_like(img0)
|
||||
imgs = it.chain([img0], imgs)
|
||||
rows = grouper(w, imgs, pad)
|
||||
return np.vstack(map(np.hstack, rows))
|
||||
return np.vstack(list(map(np.hstack, rows)))
|
||||
|
||||
def getsize(img):
|
||||
h, w = img.shape[:2]
|
||||
|
||||
@@ -191,3 +191,4 @@ if __name__ == '__main__':
|
||||
model.save('digits_svm.dat')
|
||||
|
||||
cv.waitKey(0)
|
||||
cv.destroyAllWindows()
|
||||
|
||||
@@ -29,7 +29,7 @@ def main():
|
||||
src = sys.argv[1]
|
||||
except:
|
||||
src = 0
|
||||
cap = video.create_capture(src)
|
||||
cap = video.create_capture(src, fallback='synth:bg={}:noise=0.05'.format(cv.samples.findFile('sudoku.png')))
|
||||
|
||||
classifier_fn = 'digits_svm.dat'
|
||||
if not os.path.exists(classifier_fn):
|
||||
|
||||
@@ -39,13 +39,13 @@ def main():
|
||||
except:
|
||||
video_src = 0
|
||||
args = dict(args)
|
||||
cascade_fn = args.get('--cascade', "data/haarcascades/haarcascade_frontalface_alt.xml")
|
||||
nested_fn = args.get('--nested-cascade', "data/haarcascades/haarcascade_eye.xml")
|
||||
cascade_fn = args.get('--cascade', "haarcascades/haarcascade_frontalface_alt.xml")
|
||||
nested_fn = args.get('--nested-cascade', "haarcascades/haarcascade_eye.xml")
|
||||
|
||||
cascade = cv.CascadeClassifier(cv.samples.findFile(cascade_fn))
|
||||
nested = cv.CascadeClassifier(cv.samples.findFile(nested_fn))
|
||||
|
||||
cam = create_capture(video_src, fallback='synth:bg={}:noise=0.05'.format(cv.samples.findFile('samples/data/lena.jpg')))
|
||||
cam = create_capture(video_src, fallback='synth:bg={}:noise=0.05'.format(cv.samples.findFile('lena.jpg')))
|
||||
|
||||
while True:
|
||||
_ret, img = cam.read()
|
||||
|
||||
@@ -245,4 +245,6 @@ def main():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(__doc__)
|
||||
main()
|
||||
cv.destroyAllWindows()
|
||||
|
||||
@@ -246,9 +246,9 @@ def get_matcher(args):
|
||||
if matcher_type == "affine":
|
||||
matcher = cv.detail_AffineBestOf2NearestMatcher(False, try_cuda, match_conf)
|
||||
elif range_width == -1:
|
||||
matcher = cv.detail.BestOf2NearestMatcher_create(try_cuda, match_conf)
|
||||
matcher = cv.detail_BestOf2NearestMatcher(try_cuda, match_conf)
|
||||
else:
|
||||
matcher = cv.detail.BestOf2NearestRangeMatcher_create(range_width, try_cuda, match_conf)
|
||||
matcher = cv.detail_BestOf2NearestRangeMatcher(range_width, try_cuda, match_conf)
|
||||
return matcher
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import argparse
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-i", "--image", required=True, help="path to input image file")
|
||||
parser.add_argument("-i", "--image", default="imageTextR.png", help="path to input image file")
|
||||
args = vars(parser.parse_args())
|
||||
|
||||
# load the image from disk
|
||||
@@ -37,9 +37,9 @@ def main():
|
||||
coords = cv.findNonZero(thresh)
|
||||
angle = cv.minAreaRect(coords)[-1]
|
||||
# the `cv.minAreaRect` function returns values in the
|
||||
# range [-90, 0) if the angle is less than -45 we need to add 90 to it
|
||||
if angle < -45:
|
||||
angle = (90 + angle)
|
||||
# range [0, 90) if the angle is more than 45 we need to subtract 90 from it
|
||||
if angle > 45:
|
||||
angle = (angle - 90)
|
||||
|
||||
(h, w) = image.shape[:2]
|
||||
center = (w // 2, h // 2)
|
||||
@@ -55,4 +55,6 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(__doc__)
|
||||
main()
|
||||
cv.destroyAllWindows()
|
||||
|
||||
+32
-36
@@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
'''
|
||||
Tracker demo
|
||||
|
||||
@@ -36,43 +35,49 @@ class App(object):
|
||||
|
||||
def __init__(self, args):
|
||||
self.args = args
|
||||
self.trackerAlgorithm = args.tracker_algo
|
||||
self.tracker = self.createTracker()
|
||||
|
||||
def initializeTracker(self, image, trackerAlgorithm):
|
||||
def createTracker(self):
|
||||
if self.trackerAlgorithm == 'mil':
|
||||
tracker = cv.TrackerMIL_create()
|
||||
elif self.trackerAlgorithm == 'goturn':
|
||||
params = cv.TrackerGOTURN_Params()
|
||||
params.modelTxt = self.args.goturn
|
||||
params.modelBin = self.args.goturn_model
|
||||
tracker = cv.TrackerGOTURN_create(params)
|
||||
elif self.trackerAlgorithm == 'dasiamrpn':
|
||||
params = cv.TrackerDaSiamRPN_Params()
|
||||
params.model = self.args.dasiamrpn_net
|
||||
params.kernel_cls1 = self.args.dasiamrpn_kernel_cls1
|
||||
params.kernel_r1 = self.args.dasiamrpn_kernel_r1
|
||||
tracker = cv.TrackerDaSiamRPN_create(params)
|
||||
else:
|
||||
sys.exit("Tracker {} is not recognized. Please use one of three available: mil, goturn, dasiamrpn.".format(self.trackerAlgorithm))
|
||||
return tracker
|
||||
|
||||
def initializeTracker(self, image):
|
||||
while True:
|
||||
if trackerAlgorithm == 'mil':
|
||||
tracker = cv.TrackerMIL_create()
|
||||
elif trackerAlgorithm == 'goturn':
|
||||
params = cv.TrackerGOTURN_Params()
|
||||
params.modelTxt = self.args.goturn
|
||||
params.modelBin = self.args.goturn_model
|
||||
tracker = cv.TrackerGOTURN_create(params)
|
||||
elif trackerAlgorithm == 'dasiamrpn':
|
||||
params = cv.TrackerDaSiamRPN_Params()
|
||||
params.model = self.args.dasiamrpn_net
|
||||
params.kernel_cls1 = self.args.dasiamrpn_kernel_cls1
|
||||
params.kernel_r1 = self.args.dasiamrpn_kernel_r1
|
||||
tracker = cv.TrackerDaSiamRPN_create(params)
|
||||
else:
|
||||
sys.exit("Tracker {} is not recognized. Please use one of three available: mil, goturn, dasiamrpn.".format(trackerAlgorithm))
|
||||
|
||||
print('==> Select object ROI for tracker ...')
|
||||
bbox = cv.selectROI('tracking', image)
|
||||
print('ROI: {}'.format(bbox))
|
||||
if bbox[2] <= 0 or bbox[3] <= 0:
|
||||
sys.exit("ROI selection cancelled. Exiting...")
|
||||
|
||||
try:
|
||||
tracker.init(image, bbox)
|
||||
self.tracker.init(image, bbox)
|
||||
except Exception as e:
|
||||
print('Unable to initialize tracker with requested bounding box. Is there any object?')
|
||||
print(e)
|
||||
print('Try again ...')
|
||||
continue
|
||||
|
||||
return tracker
|
||||
return
|
||||
|
||||
def run(self):
|
||||
videoPath = self.args.input
|
||||
trackerAlgorithm = self.args.tracker_algo
|
||||
camera = create_capture(videoPath, presets['cube'])
|
||||
print('Using video: {}'.format(videoPath))
|
||||
camera = create_capture(cv.samples.findFileOrKeep(videoPath), presets['cube'])
|
||||
if not camera.isOpened():
|
||||
sys.exit("Can't open video stream: {}".format(videoPath))
|
||||
|
||||
@@ -82,7 +87,7 @@ class App(object):
|
||||
assert image is not None
|
||||
|
||||
cv.namedWindow('tracking')
|
||||
tracker = self.initializeTracker(image, trackerAlgorithm)
|
||||
self.initializeTracker(image)
|
||||
|
||||
print("==> Tracking is started. Press 'SPACE' to re-initialize tracker or 'ESC' for exit...")
|
||||
|
||||
@@ -92,7 +97,7 @@ class App(object):
|
||||
print("Can't read frame")
|
||||
break
|
||||
|
||||
ok, newbox = tracker.update(image)
|
||||
ok, newbox = self.tracker.update(image)
|
||||
#print(ok, newbox)
|
||||
|
||||
if ok:
|
||||
@@ -101,7 +106,7 @@ class App(object):
|
||||
cv.imshow("tracking", image)
|
||||
k = cv.waitKey(1)
|
||||
if k == 32: # SPACE
|
||||
tracker = self.initializeTracker(image)
|
||||
self.initializeTracker(image)
|
||||
if k == 27: # ESC
|
||||
break
|
||||
|
||||
@@ -112,22 +117,13 @@ if __name__ == '__main__':
|
||||
print(__doc__)
|
||||
parser = argparse.ArgumentParser(description="Run tracker")
|
||||
parser.add_argument("--input", type=str, default="vtest.avi", help="Path to video source")
|
||||
parser.add_argument("--tracker_algo", type=str, default="mil", help="One of three available tracking algorithms: mil, goturn, dasiamrpn")
|
||||
parser.add_argument("--tracker_algo", type=str, default="mil", help="One of available tracking algorithms: mil, goturn, dasiamrpn")
|
||||
parser.add_argument("--goturn", type=str, default="goturn.prototxt", help="Path to GOTURN architecture")
|
||||
parser.add_argument("--goturn_model", type=str, default="goturn.caffemodel", help="Path to GOTERN model")
|
||||
parser.add_argument("--dasiamrpn_net", type=str, default="dasiamrpn_model.onnx", help="Path to onnx model of DaSiamRPN net")
|
||||
parser.add_argument("--dasiamrpn_kernel_r1", type=str, default="dasiamrpn_kernel_r1.onnx", help="Path to onnx model of DaSiamRPN kernel_r1")
|
||||
parser.add_argument("--dasiamrpn_kernel_cls1", type=str, default="dasiamrpn_kernel_cls1.onnx", help="Path to onnx model of DaSiamRPN kernel_cls1")
|
||||
parser.add_argument("--dasiamrpn_backend", type=int, default=0, help="Choose one of computation backends:\
|
||||
0: automatically (by default),\
|
||||
1: Halide language (http://halide-lang.org/),\
|
||||
2: Intel's Deep Learning Inference Engine (https://software.intel.com/openvino-toolkit),\
|
||||
3: OpenCV implementation")
|
||||
parser.add_argument("--dasiamrpn_target", type=int, default=0, help="Choose one of target computation devices:\
|
||||
0: CPU target (by default),\
|
||||
1: OpenCL,\
|
||||
2: OpenCL fp16 (half-float precision),\
|
||||
3: VPU")
|
||||
|
||||
args = parser.parse_args()
|
||||
App(args).run()
|
||||
cv.destroyAllWindows()
|
||||
|
||||
Reference in New Issue
Block a user