Issue 1:
hi

import cv2

cap=cv2.VideoCapture("set/your/file/here")
w = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
cnt = cap.get(cv2.CAP_PROP_FRAME_COUNT)
print("Opencv width %d frames %d"%(w,cnt))

cap.read()
ts= cap.get(cv2.CAP_PROP_POS_MSEC)
print("ts @ frame 0 after read %.3f"%ts)

i have run this on my PC and got different results in different versions:

after 4.1.2:
ts @ frame 0 after read 0.000

before 4.1.1:
ts @ frame 0 after read 40.000

so i am a little confused.

which one is (will be) correct in the future?

what is the actual meaning of these timestamps? (start time ? end time ? )

thanks

Issue 2:
System information (version)

OpenCV => 3.4.1

Operating System / Platform => windows 64

Compiler => visual studio 2017

Detailed description

Trained a model on tensorflow for 2 classes.

I'm using the sample Opencv dnn code to call my .pb file, and it predicts only one single class. Specifically the second class (second line) from labels text file.

My C++ code for inference: (note - for input blob I factored to scale 1/127, swapped channels and also did mean subtraction but to no luck)

// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.

// Copyright (C) 2016, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.

/*
Sample of using OpenCV dnn module with Tensorflow Inception model.
*/

#include <stdafx.h>
using namespace cv;
using namespace cv::dnn;

#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;

const String keys =
"{help h || Sample app for loading Inception TensorFlow model. "
"The model and class names list can be downloaded here: "
"https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip }"
"{model m |tensorflow_inception_graph.pb| path to TensorFlow .pb model file }"
"{image i || path to image file }"
"{i_blob | input | input blob name) }"
"{o_blob | softmax2 | output blob name) }"
"{c_names c | imagenet_comp_graph_label_strings.txt | path to file with classnames for class id }"
"{result r || path to save output blob (optional, binary format, NCHW order) }"
;

void getMaxClass(const Mat &probBlob, int *classId, double *classProb);
std::vector<String> readClassNames(const char *filename);

int main(int argc, char **argv)
{
cv::CommandLineParser parser(argc, argv, keys);

if (parser.has("help"))
{
parser.printMessage();
return 0;
}

String modelFile = "OptimizedGraph.pb";
String imageFile = "img.JPG";
String inBlobName = "input";
String outBlobName = "side";
if (!parser.check())
{
parser.printErrors();
return 0;
}

String classNamesFile = "imagenet_comp_graph_label_strings.txt";
String resultFile = "output.txt";

//! [Initialize network]
dnn::Net net = readNetFromTensorflow(modelFile);
//! [Initialize network]

if (net.empty())
{
std::cerr << "Can't load network by using the mode file: " << std::endl;
std::cerr << modelFile << std::endl;
exit(-1);
}

//! [Prepare blob]
Mat img = imread(imageFile);
if (img.empty())
{
std::cerr << "Can't read image from the file: " << imageFile << std::endl;
exit(-1);
}

Mat inputBlob = blobFromImage(img, 0.00784, Size(160, 160),Scalar(127.5,127.5,127.5), true, false); //Convert Mat to batch of images
//! [Prepare blob]
inputBlob -= 117.0;
//! [Set input blob]
net.setInput(inputBlob, inBlobName); //set the network input
//! [Set input blob]

cv::TickMeter tm;
tm.start();

//! [Make forward pass]
Mat result = net.forward(outBlobName); //compute output
//! [Make forward pass]

tm.stop();

if (!resultFile.empty()) {
CV_Assert(result.isContinuous());

ofstream fout(resultFile.c_str(), ios::out | ios::binary);
fout.write((char*)result.data, result.total() * sizeof(float));
fout.close();
}

std::cout << "Output blob shape " << result.size[0] << " x " << result.size[1] << " x " << result.size[2] << " x " << result.size[3] << std::endl;
std::cout << "Inference time, ms: " << tm.getTimeMilli() << std::endl;

if (!classNamesFile.empty()) {
std::vector<String> classNames = readClassNames(classNamesFile.c_str());

int classId;
double classProb;
getMaxClass(result, &classId, &classProb);//find the best class

//! [Print results]
std::cout << "Best class: #" << classId << " '" << classNames.at(classId) << "'" << std::endl;
std::cout << "Probability: " << classProb * 100 << "%" << std::endl;
}
return 0;
} //main

/* Find best class for the blob (i. e. class with maximal probability) */
void getMaxClass(const Mat &probBlob, int *classId, double *classProb)
{
Mat probMat = probBlob.reshape(1, 1); //reshape the blob to 1x1000 matrix
Point classNumber;

minMaxLoc(probMat, NULL, classProb, NULL, &classNumber);
*classId = classNumber.x;
}

std::vector<String> readClassNames(const char *filename)
{
std::vector<String> classNames;

std::ifstream fp(filename);
if (!fp.is_open())
{
std::cerr << "File with classes labels not found: " << filename << std::endl;
exit(-1);
}

std::string name;
while (!fp.eof())
{
std::getline(fp, name);
if (name.length())
classNames.push_back(name);
}

fp.close();
return classNames;
}

Exact output is as following:

[ INFO:0] Initialize OpenCL runtime...

Net Outputs(1):
side
Output blob shape 1 x 2 x 1090226688 x 427
Inference time, ms: 1178.1
Best class: #1 'class2'
Probability: 765.036% <-------- look at the bad prob score

My possible thoughts on why this is happening:

In TF code, I get logits from tf.slim.fully_connected. I saved this by using

logits = tf.multiply(logits,1,name='output'). Maybe this isn't the right way of saving output node?

I'm not at liberty to share the .pb file, so any comments on how to solve this?