mat

cv::Mat matrix, HOW TO Reduce digits to the right of the decimal point in cv::Mat?

依然范特西╮ 提交于 2019-12-04 07:42:50
I have an app that prints a 3x3 cv::Mat on the iPhone screen. I need to reduce the decimals, as the screen is not so big, see: [1.004596557012473, -0.003116992336797859, 5.936915104939593; -0.007241746117066327, 0.9973985665720294, -0.2118670500989478; 1.477734234970711e-05, -1.03363734495053e-05, 1.000089074805124] so I would like to reduce the decimals .4 or .6 or six decimals. Any ideas? Cheers If you were using printf cv::Mat data(3, 3, CV_64FC1); for (int y = 0; y < data.rows; ++y) { for (int x = 0;x < data.cols; ++x) { printf("%.6f ", data.at<double>(y, x)); } } If you were using std:

Knowing the value of an Mat element Opencv

最后都变了- 提交于 2019-12-04 04:53:51
问题 From my question, Can I determine the number of channels in cv::Mat Opencv I am using the same code, to find the laplacian of Gaussian of the image. The edges around the objects are well detected in the image. How can I access the single element value of the final output image, abs_dst_gray? I know I have to use the '.at' operator and I also found its datatype to be CV_8U. I tried the following cout<<abs_dst_gray.at<uchar>(10,10)<<endl; But I was not able to know wat value it holds there,

Get Mat object from Camera frame Android for OpenCV

旧时模样 提交于 2019-12-03 20:35:05
I am developing an android application based on Tutorial 2 given by OpenCV4Android. What I want to achieve is to get the Mat object of the camera frame when I touch the phone's screen ( onTouch() ). I want to modify the code such that I store the image as Mat instead of a jpeg file on the phone's memory. The Mat will then go under further processing. Do I need to involve the onCameraFrame() function? Any guidance will be much appreciated. I am very new to Android developing and OpenCV as well. Note: I am using Android version 4.2.2 and OpenCV2.4.8. Edit: After editing onTouch() and

Add the contents of 2 Mats to another Mat opencv c++

风流意气都作罢 提交于 2019-12-03 07:45:45
I just want to add the contents of 2 different Mat s to 1 other Mat . I tried: Mat1.copyTo(newMat); Mat2.copyTo(newMat); But that just seemed to overwrite the previous contents of the Mat . This may be a simple question, but I'm lost. It depends on what you want to add . For example, you have two 3x3 Mat: cv::Mat matA(3, 3, CV_8UC1, cv::Scalar(20)); cv::Mat matB(3, 3, CV_8UC1, cv::Scalar(80)); You can add matA and matB to a new 3x3 Mat with value 100 using matrix operation : auto matC = matA + matB; Or using array operation cv::add that does the same job: cv::Mat matD; cv::add(matA, matB, matD

How to divide an OpenCV Mat in rectangular sub-regions?

时光毁灭记忆、已成空白 提交于 2019-12-02 21:17:28
问题 I want to divide a simple Mat (200x200) in different regions (10x10). I make 2 loops, then I create a Rect where I indicate the variables I want in each iteration (x, y, width, height) . Finally, I save this region of the image inside a vector of Mat s. But something is wrong with my code: Mat face = Mat(200, 200, CV_8UC1); vector<Mat> regions; Mat region_frame; int width = face.cols * 0.05; int heigth = face.rows * 0.05; for(int y=0; y<=(face.rows - heigth); y+=heigth) { for(int x=0; x<=

Calling finish() does not clear memory references to Activity

时光毁灭记忆、已成空白 提交于 2019-12-02 10:17:38
问题 In a simplified version of my app, I have two activities, A and B. Actvity A starts B, and after some work B calls finish(). Using the Memory Analyzer Tool on most devices (Galaxy Nexus running 4.2, Droid 4 running 4.0.4, and Droid 2 running 2.3.4) shows no trace of activity B, which is what I expected. But on Samsung S3 running 4.1.1, MAT shows activity B objects still around, due to paths to the following GC roots (weak/soft references excluded): Class Name | Shallow Heap | Retained Heap --

Select a subset of a Mat and copy them to create a new mat in C++/Opencv

限于喜欢 提交于 2019-12-02 04:15:31
问题 In C++/opencv, how can I select a subset of a big Mat and copy them to create a new Mat? I know how to use copyto, colrange, rowrange, etc., but don't know to combine them together to develop a decent and efficient code. Thanks! 回答1: You can use copyTo() for this purpose: //copy a sub matrix of X to Y with starting coodinate (startX,startY) // and dimension (cols,rows) cv::Mat tmp = X(cv::Rect(startX,startY,cols,rows)); cv::Mat Y; tmp.copyTo(Y); or directly: cv::Mat Y; X(cv::Rect(startX

Knowing the value of an Mat element Opencv

99封情书 提交于 2019-12-02 02:07:44
From my question, Can I determine the number of channels in cv::Mat Opencv I am using the same code, to find the laplacian of Gaussian of the image. The edges around the objects are well detected in the image. How can I access the single element value of the final output image, abs_dst_gray? I know I have to use the '.at' operator and I also found its datatype to be CV_8U. I tried the following cout<<abs_dst_gray.at<uchar>(10,10)<<endl; But I was not able to know wat value it holds there, using this method. How can I find that value? If I use int or long, I end up with garbage values. I have

Select a subset of a Mat and copy them to create a new mat in C++/Opencv

别来无恙 提交于 2019-12-02 01:04:59
In C++/opencv, how can I select a subset of a big Mat and copy them to create a new Mat? I know how to use copyto, colrange, rowrange, etc., but don't know to combine them together to develop a decent and efficient code. Thanks! fatihk You can use copyTo() for this purpose: //copy a sub matrix of X to Y with starting coodinate (startX,startY) // and dimension (cols,rows) cv::Mat tmp = X(cv::Rect(startX,startY,cols,rows)); cv::Mat Y; tmp.copyTo(Y); or directly: cv::Mat Y; X(cv::Rect(startX,startY,cols,rows)).copyTo(Y); 来源: https://stackoverflow.com/questions/17691079/select-a-subset-of-a-mat

Does a const Mat reference in OpenCV make sense?

拈花ヽ惹草 提交于 2019-12-01 23:48:04
问题 In the following function foo(const Mat& img) img can be changed in the function without even a warning by the compiler. Why? Does it mean const Mat reference don't make any sense? 回答1: That is because a Mat contains a pointer to the actual image data. The const applies only to the Mat object itself (e.g. attributes like rows, cols) and not to the data referred to by the pointer. Note: even if the function was foo(Mat img) you could still change the image data. There are a number of