Replies: 4 comments 13 replies
-
Use mat(): http://dlib.net/linear_algebra.html#mat |
Beta Was this translation helpful? Give feedback.
-
I performed some tests on this, and I think it could be done more efficiently, by adding some new functions in For testing purposes only, I added the following method to void assign_ptr(T* ptr, int rows, int cols) {
data.set_size(rows, cols);
T* d = &data(0,0);
T* aux = ptr;
for (int i=0; i<rows*cols; i++)
*d++ = *aux++;
} I ran this on my computer, with an I5-9400, using Docker image #include <opencv2/opencv.hpp>
#include <dlib/matrix.h>
#include <dlib/opencv.h>
#include <dlib/image_transforms/assign_image.h>
int main(int argc, char** argv) {
cv::VideoCapture cap("/* path to some video */");
cv::Mat frame, gray;
long long ans = 0, sumTime = 0, counter = 0;
cap >> frame;
dlib::matrix<unsigned char> aux(frame.rows, frame.cols);
while (!frame.empty()) {
cv::cvtColor(frame, gray, cv::COLOR_BGR2GRAY);
auto t1 = std::chrono::high_resolution_clock::now();
// uncomment the option you want to test
dlib::assign_image<dlib::matrix<unsigned char>, dlib::cv_image<unsigned char>>(aux, gray);
//aux = dlib::mat(gray.data, gray.rows, gray.cols);
//aux.assign_ptr(gray.data, gray.rows, gray.cols);
auto t2 = std::chrono::high_resolution_clock::now();
sumTime += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
ans += dlib::sum(aux);
cap >> frame;
counter++;
if (counter >= 1000) break;
}
std::cout << "Avg time: " << sumTime / counter << std::endl;
std::cout << "Sum of mats " << ans << std::endl;
return 0;
} With HD (1280x720) videos, this was the result (after multiple executions):
With Full HD (1920x1080) videos, this was the result (after multiple executions):
After looking at these results, I think it would be a good idea to add something like this to Anyway, I also thought about the possibility that I'm misusing the two existing ways of copying the frame. If that's the case, please help me fix it, and I can run the tests again. |
Beta Was this translation helpful? Give feedback.
-
@facug91 You don't have to use |
Beta Was this translation helpful? Give feedback.
-
Hi I stumbled upon a similar problem. I am trying to use svm_multiclass_linear_trainer, but I have to convert my original data (which is an arma::mat) into a std::vectordlib::matrix. I had tried mat() but seems it's not working (I guess it's because it has to be casted as an actual matrix anyway). Would there be any solution to this? |
Beta Was this translation helpful? Give feedback.
-
I have huge data sets. So I don't want to copy existing 2D (type **) or 3D (type ***) c++ arrays to a matrix. I want to create a matrix using existing memory already allocated. How to do this?
Beta Was this translation helpful? Give feedback.
All reactions