Skip to content

Instantly share code, notes, and snippets.

@takiyu
Created May 23, 2017 12:17
Show Gist options
  • Save takiyu/ed1a622d1f1d8202a5aa72b02cf30e1d to your computer and use it in GitHub Desktop.
Save takiyu/ed1a622d1f1d8202a5aa72b02cf30e1d to your computer and use it in GitHub Desktop.
Sample of cv::Mat creation from const float*
#include <iostream>
#include <opencv2/core.hpp>
int main(int argc, char const* argv[]) {
static const float d[] = {1, 2, 3};
cv::Mat m(1, 3, CV_32FC1, const_cast<float *>(d));
printf("Address d: %p\n", d);
printf("Address m: %p\n", m.data);
// Calculation with changes
// std::cout << "prev: " << m.at<float>(0) << std::endl;
// m.at<float>(0) += 1; // Cause segmentation fault
// std::cout << "post: " << m.at<float>(0) << std::endl;
// Calculation with no changes
float res = m.dot(m);
std::cout << res << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment