mirror of
https://github.com/opencv/opencv.git
synced 2025-06-11 20:09:23 +08:00
samples: use findFile() in dnn
This commit is contained in:
parent
c4c31f5bba
commit
e8e2197032
@ -64,9 +64,9 @@ int main(int argc, char **argv)
|
||||
parser.printMessage();
|
||||
return 0;
|
||||
}
|
||||
string modelTxt = parser.get<string>("proto");
|
||||
string modelBin = parser.get<string>("model");
|
||||
string imageFile = parser.get<string>("image");
|
||||
string modelTxt = samples::findFile(parser.get<string>("proto"));
|
||||
string modelBin = samples::findFile(parser.get<string>("model"));
|
||||
string imageFile = samples::findFile(parser.get<string>("image"));
|
||||
bool useOpenCL = parser.has("opencl");
|
||||
if (!parser.check())
|
||||
{
|
||||
|
@ -86,6 +86,10 @@ def findFile(filename):
|
||||
if os.path.exists(filename):
|
||||
return filename
|
||||
|
||||
fpath = cv.samples.findFile(filename, False)
|
||||
if fpath:
|
||||
return fpath
|
||||
|
||||
samplesDataDir = os.path.join(os.path.dirname(os.path.abspath(__file__)),
|
||||
'..',
|
||||
'data',
|
||||
|
@ -43,7 +43,7 @@ cv.dnn_registerLayer('Crop', CropLayer)
|
||||
#! [Register]
|
||||
|
||||
# Load the model.
|
||||
net = cv.dnn.readNet(args.prototxt, args.caffemodel)
|
||||
net = cv.dnn.readNet(cv.samples.findFile(args.prototxt), cv.samples.findFile(args.caffemodel))
|
||||
|
||||
kWinName = 'Holistically-Nested Edge Detection'
|
||||
cv.namedWindow('Input', cv.WINDOW_NORMAL)
|
||||
|
@ -13,7 +13,7 @@ parser.add_argument('--height', default=-1, type=int, help='Resize input to spec
|
||||
parser.add_argument('--median_filter', default=0, type=int, help='Kernel size of postprocessing blurring.')
|
||||
args = parser.parse_args()
|
||||
|
||||
net = cv.dnn.readNetFromTorch(args.model)
|
||||
net = cv.dnn.readNetFromTorch(cv.samples.findFile(args.model))
|
||||
net.setPreferableBackend(cv.dnn.DNN_BACKEND_OPENCV);
|
||||
|
||||
if args.input:
|
||||
|
@ -68,13 +68,13 @@ def drawBox(frame, classId, conf, left, top, right, bottom):
|
||||
|
||||
|
||||
# Load a network
|
||||
net = cv.dnn.readNet(args.model, args.config)
|
||||
net = cv.dnn.readNet(cv.samples.findFile(args.model), cv.samples.findFile(args.config))
|
||||
net.setPreferableBackend(cv.dnn.DNN_BACKEND_OPENCV)
|
||||
|
||||
winName = 'Mask-RCNN in OpenCV'
|
||||
cv.namedWindow(winName, cv.WINDOW_NORMAL)
|
||||
|
||||
cap = cv.VideoCapture(args.input if args.input else 0)
|
||||
cap = cv.VideoCapture(cv.samples.findFileOrKeep(args.input) if args.input else 0)
|
||||
legend = None
|
||||
while cv.waitKey(1) < 0:
|
||||
hasFrame, frame = cap.read()
|
||||
|
@ -26,12 +26,12 @@ parser.add_argument('--annotations', help='Path to COCO annotations file.', requ
|
||||
args = parser.parse_args()
|
||||
|
||||
### Get OpenCV predictions #####################################################
|
||||
net = cv.dnn.readNetFromTensorflow(args.weights, args.prototxt)
|
||||
net = cv.dnn.readNetFromTensorflow(cv.samples.findFile(args.weights), cv.samples.findFile(args.prototxt))
|
||||
net.setPreferableBackend(cv.dnn.DNN_BACKEND_OPENCV);
|
||||
|
||||
detections = []
|
||||
for imgName in os.listdir(args.images):
|
||||
inp = cv.imread(os.path.join(args.images, imgName))
|
||||
inp = cv.imread(cv.samples.findFile(os.path.join(args.images, imgName)))
|
||||
rows = inp.shape[0]
|
||||
cols = inp.shape[1]
|
||||
inp = cv.resize(inp, (300, 300))
|
||||
|
@ -67,7 +67,7 @@ if args.classes:
|
||||
classes = f.read().rstrip('\n').split('\n')
|
||||
|
||||
# Load a network
|
||||
net = cv.dnn.readNet(args.model, args.config, args.framework)
|
||||
net = cv.dnn.readNet(cv.samples.findFile(args.model), cv.samples.findFile(args.config), args.framework)
|
||||
net.setPreferableBackend(args.backend)
|
||||
net.setPreferableTarget(args.target)
|
||||
outNames = net.getUnconnectedOutLayersNames()
|
||||
@ -182,7 +182,7 @@ def callback(pos):
|
||||
|
||||
cv.createTrackbar('Confidence threshold, %', winName, int(confThreshold * 100), 99, callback)
|
||||
|
||||
cap = cv.VideoCapture(args.input if args.input else 0)
|
||||
cap = cv.VideoCapture(cv.samples.findFileOrKeep(args.input) if args.input else 0)
|
||||
while cv.waitKey(1) < 0:
|
||||
hasFrame, frame = cap.read()
|
||||
if not hasFrame:
|
||||
|
@ -66,9 +66,9 @@ int main(int argc, char **argv)
|
||||
"{ t threshold | 0.1 | threshold or confidence value for the heatmap }"
|
||||
);
|
||||
|
||||
String modelTxt = parser.get<string>("proto");
|
||||
String modelBin = parser.get<string>("model");
|
||||
String imageFile = parser.get<String>("image");
|
||||
String modelTxt = samples::findFile(parser.get<string>("proto"));
|
||||
String modelBin = samples::findFile(parser.get<string>("model"));
|
||||
String imageFile = samples::findFile(parser.get<String>("image"));
|
||||
int W_in = parser.get<int>("width");
|
||||
int H_in = parser.get<int>("height");
|
||||
float thresh = parser.get<float>("threshold");
|
||||
|
@ -45,7 +45,7 @@ else:
|
||||
inWidth = args.width
|
||||
inHeight = args.height
|
||||
|
||||
net = cv.dnn.readNetFromCaffe(args.proto, args.model)
|
||||
net = cv.dnn.readNetFromCaffe(cv.samples.findFile(args.proto), cv.samples.findFile(args.model))
|
||||
|
||||
cap = cv.VideoCapture(args.input if args.input else 0)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user