2017-03-06 10:07:00 -0600
| received badge | ● Necromancer
(source)
|
2017-03-06 09:21:04 -0600
| received badge | ● Necromancer
(source)
|
2017-03-06 08:43:23 -0600
| answered a question | UMat get values No. UMat represents a memory object that resides on the GPU. You have to use getMat to copy the data to the CPU to manipulate it. |
2017-03-06 08:33:56 -0600
| answered a question | CV::Mat crashes on release or when out of scope Because Tester(-1) saves some bookkeeping data when the memory is allocated. Since you changed it, it crashes when it tries to free the memory! Please only do operations to the memory that you have allocated. Reference: void* fastMalloc( size_t size )
at
https://github.com/opencv/opencv/blob... |
2017-03-06 08:28:03 -0600
| answered a question | operations on cv::Point Here is an example about some operations defined on cv::Point and cv::Point3 cv::point pp; // pp.x = pp.y = 0;
int x = 1, y = 2;
cv::Point p(x, y)
int width = 1, height = 2;
cv::Size sz(width, height);
cv::Point p(sz); // p.x = sz.width; p.y = sz.height;
cv::Point p2(p); // copy constructor
p2 = p; // assignment operator
int i = p.dot(p2); // may suffer saturation
double d = p.ddot(p2); // dot product, always return double
double d2 = p.cross(p2); // cross product, always return double
double d3 = norm(p); // 2-norm, retur double
cv::Point p3;
p += p1;
p = p1 + p2;
p -= p1;
p = p1 - p2;
p = -p1;
p == p1; // true or false
p != p1; // true or false
int s;
p *= s;
p = p1 * s;
p = s * p1;
p /= s;
p = p1 / s;
cv::Point3f p; // p.x = p.y = p.z = 0; default constructor
int x = 1, y = 2, z = 3;
cv::Point3f p1(x, y, z);
cv::Point2f p2(x, y);
cv::Point3f p3(p1); // copy constructor
p = p1; // assignment operator
cv::Point3f p4(p2); p4.x = p2.x; p4.y = p2.y; p4.z = 0;
float f1 = p1.dot(p3); // dot product, potential saturation for uint8_t
double d1 = p1.ddot(p3); // dot product, always return double
double mag = norm(p1); // return the magnitude of the point. Return type is double.
p4 = p1.cross(p3); // cross product
p = p1 + p3;
p += p1;
p = p1 - p3;
p -= p3;
p = -p3;
p1 == p3; // true or false
p1 != p3;
float s = 3;
p = p * s;
p = s * p;
p *= s;
p = p / s;
p /= s;
|
2017-03-06 08:17:10 -0600
| answered a question | How to Create an image from pixels in memory? Here is an example: int main(int argc, char *argv[])
{
int data[] = { 1,2,3,4,5,6,7,8,9 };
cv::Mat m(3, 3, CV_32S, data);
std::cout << m << std::endl;
return 0;
}
And the output is [1, 2, 3;
4, 5, 6;
7, 8, 9]
|
2017-03-06 08:12:35 -0600
| answered a question | How to add 2 Mat objects of different type? You can use the method cv::add, which is called indirectly by the operator +.
An example is as follows. int main(int argc, char *argv[])
{
const cv::Mat A(10, 20, CV_32FC1, cv::Scalar::all(CV_PI));
const cv::Mat B(A.size(), CV_8UC1, cv::Scalar::all(10));
cv::Mat C;
cv::add(A, B, C, cv::noArray(), A.type());
return 0;
}
|
2017-03-06 08:06:04 -0600
| received badge | ● Editor
(source)
|
2017-03-06 08:00:59 -0600
| answered a question | Comparing two images whether same or not You can use the function cv::countNonZero, which count the number of elements that are not zero in the Mat. An example is following: int main(int argc, char *argv[])
{
cv::Mat m1(2, 2, CV_32SC1);
cv::Mat m2(2, 2, CV_32SC1);
m1 = cv::Scalar::all(2);
m2 = cv::Scalar::all(2);
if (cv::countNonZero(m1 - m2) != 0)
{
std::cout << "m1 != m2" << std::endl;
}
else
{
std::cout << "m1 == m2" << std::endl;
}
return 0;
}
Or use could use cv::sum int main(int argc, char *argv[])
{
cv::Mat m1(2, 2, CV_32SC1);
cv::Mat m2(2, 2, CV_32SC1);
m1 = cv::Scalar::all(2);
m2 = cv::Scalar::all(2);
if (cv::sum(m1 - m2) != cv::Scalar(0))
{
std::cout << "m1 != m2" << std::endl;
}
else
{
std::cout << "m1 == m2" << std::endl;
}
return 0;
}
Instead of using m1 - m2, you could also use xor: m1 ^ m2 |
2017-03-06 07:39:47 -0600
| answered a question | What is InputArray? Actually you can modify the underlying Mat through InputArray: int main(int argc, char *argv[])
{
cv::Mat m1(2, 2, CV_32SC1);
cv::InputArray arr(m1);
cv::Mat m2 = arr.getMat();
m2 = cv::Scalar::all(2);
std::cout << m1 << std::endl;
return 0;
}
The output is [2, 2;
2, 2]
But it is a convention that you should perform only read operations on it. |