Understanding pcl::getMinMax3D() - pcl

I have a point cloud data with wide range in all 3 dimensions. I have filtered it using pcl::ConditionalRemoval::filter() in range -20 >= x >= 20, -20 >= y >= 20 and -2 >= z >= 2.
Now I want to have min and max values in each dimension, so I searched online for nay PCL function. I got pcl::getMinMax3D. I used it and to verify I also manually searched in the cloud data. The code is as below:
float xmin = 10000, xmax=-10000;
cout << "Manual Search Result:"<<endl;
for(unsigned int i = 0; i < filtered_data->size(); i++)
{
if(filtered_data->at(i)._PointXYZ::x > xmax)
xmax = filtered_data->at(i)._PointXYZ::x;
if(filtered_data->at(i)._PointXYZ::x < xmin)
xmin = filtered_data->at(i)._PointXYZ::x;
}
cout << "Xmin: " << xmin << "\t\tXmax: " << xmax << endl;
float ymin = 10000, ymax=-10000;
for(unsigned int i = 0; i < filtered_data->size(); i++)
{
if(filtered_data->at(i)._PointXYZ::y > ymax)
ymax = filtered_data->at(i)._PointXYZ::y;
if(filtered_data->at(i)._PointXYZ::y < ymin)
ymin = filtered_data->at(i)._PointXYZ::y;
}
cout << "Ymin: " << ymin << "\t\tYmax: " << ymax << endl;
float zmin = 10000, zmax=-10000;
for(unsigned int i = 0; i < filtered_data->size(); i++)
{
if(filtered_data->at(i)._PointXYZ::z > zmax)
zmax = filtered_data->at(i)._PointXYZ::z;
if(filtered_data->at(i)._PointXYZ::z < zmin)
zmin = filtered_data->at(i)._PointXYZ::z;
}
cout << "Zmin: " << zmin << "\t\tZmax: " << zmax << endl;
pcl::PointXYZ minPt, maxPt;
pcl::getMinMax3D (*filtered_data, minPt, maxPt);
cout << "getMinMax3D Search Result:"<<endl;
std::cout << "Min x: " << minPt.x << "\t\tMax x: " << maxPt.x << std::endl;
std::cout << "Min y: " << minPt.y << "\t\tMax y: " << maxPt.y << std::endl;
std::cout << "Min z: " << minPt.z << "\t\tMax z: " << maxPt.z << std::endl;
The output I m getting is:
Manual Search Result:
Xmin: -19.992 Xmax: 19.915
Ymin: -19.75 Ymax: 19.982
Zmin: -1.999 Zmax: 1.059
getMinMax3D Search Result:
Min x: -3.895 Max x: 3.967
Min y: -4.238 Max y: 4.291
Min z: -1.887 Max z: 0
Is my understanding wrong about the usage of getMinMax3D()?

If the input cloud has NAN point, make sure you set cloud.is_dense as false, otherwise the function pcl::getMinMax3D would not check for NaN.
Here is original implementation from https://pointclouds.org/documentation/common_2include_2pcl_2common_2impl_2common_8hpp_source.html
template <typename PointT> inline void
pcl::getPointsInBox (const pcl::PointCloud<PointT> &cloud,
Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt,
Indices &indices)
{
indices.resize (cloud.size ());
int l = 0;
// If the data is dense, we don't need to check for NaN
if (cloud.is_dense)
{
for (std::size_t i = 0; i < cloud.size (); ++i)
{
// Check if the point is inside bounds
if (cloud[i].x < min_pt[0] || cloud[i].y < min_pt[1] || cloud[i].z < min_pt[2])
continue;
if (cloud[i].x > max_pt[0] || cloud[i].y > max_pt[1] || cloud[i].z > max_pt[2])
continue;
indices[l++] = int (i);
}
}
// NaN or Inf values could exist => check for them
else
{
for (std::size_t i = 0; i < cloud.size (); ++i)
{
// Check if the point is invalid
if (!std::isfinite (cloud[i].x) ||
!std::isfinite (cloud[i].y) ||
!std::isfinite (cloud[i].z))
continue;
// Check if the point is inside bounds
if (cloud[i].x < min_pt[0] || cloud[i].y < min_pt[1] || cloud[i].z < min_pt[2])
continue;
if (cloud[i].x > max_pt[0] || cloud[i].y > max_pt[1] || cloud[i].z > max_pt[2])
continue;
indices[l++] = int (i);
}
}
indices.resize (l);
}

Related

Explain the logic of the output please

I am new to C++. I know the output would be 1024, 10.
I just have no clue as to why log would print out 10, instead of 1.
int n = 1024;
int log = 0;
for (int i = 1; i < n; i = i * 2);
log++;
cout << n << " " << log << endl;
I believe you are missing just the brackets if you are trying to iterate over the loop and print out the log.
int n = 1024;
int log = 0;
for (int i = 1; i < n; i = i * 2)
{
log++;
cout << n << " " << log << endl;
}

Minim of the even elements of the matrix and the maximum of the prime elements

I have to calculateand then display in OOP of C++
Minimum of the even elements of the matrix and the maximum of the prime elements
As i made up my code
My problem is that i have no idea how to make so that the max value from a matrix to be a prime number and I have no clue if I should work with a for( ) and then use a if (value%i==0) or if there can be a better method.
#include <iostream>
using namespace std;
class matrix3
{
int a[10][10], b[10][10], c[10][10], d[10][10], e[10][10], f[10][10], x, y, i, j, l1,l2,max, max2 = 0, min = 0, save, c1, c2;
public:
void values();
void transpose();
void sum();
void diff();
void linie();
void coloana();
void minimul_elementelor_pare();
void maximul_elementelor_prime();
};
void matrix3::values()
{
cout << "Enter the rows "; cin >> x;
cout << "Enter the columns "; cin >> y;
cout << "Enter elements of first matrix\n\n";
for (i = 1; i <= x; i++)
{
for (j = 1; j <= y; j++)
{
cin >> a[i][j];
}
}
cout << "Enter elements of second matrix\n\n";
for (i = 1; i <= x; i++)
{
for (j = 1; j <= y; j++)
{
cin >> c[i][j];
}
}
}
void matrix3::sum()
{
cout << "Sum of Matrices 1 and 2 is\n";
for (i = 1; i <= x; i++)
{
for (j = 1; j <= y; j++)
{
e[i][j] = a[i][j] + c[i][j];
cout << e[i][j] << "";
}
cout << endl;
}
}
void matrix3::diff()
{
cout << "Difference of Matrices 1 and 2 (1-2) is\n";
for (i = 1; i <= x; i++)
{
for (j = 1; j <= y; j++)
{
f[i][j] = a[i][j] - c[i][j];
cout << f[i][j] << "";
}
cout << endl;
}
}
void matrix3::transpose()
{
cout << "transpose of the matrix is\n";
for (i = 1; i <= x; i++)
{
for (j = 1; j <= y; j++)
{
b[i][j] = a[j][i];
cout << b[i][j] << "";
}
cout << endl;
}
cout << "Transpose of the second matrix is\n";
for (i = 1; i <= x; i++)
{
for (j = 1; j <= y; j++)
{
d[i][j] = c[j][i];
cout << b[i][j] << "";
}
cout << endl;
}
}
void matrix3::coloana()
{
cout << "test is\n";
cout << "\n Numerele coloanelor care doriti sa le interschimbati";
cout << "\n c1: ";cin >> c1;
cout << "\n c2: ";cin >> c2;
for (i = 1; i <= x; i++)
{
save = a[i][c1];
a[i][c1] = a[i][c2];
a[i][c2] = save;
}
for (i = 1;i <= x;i++) {
for (j = 1;j <= y;j++) {
cout << a[i][j] << " ";
}
cout << endl;
}
}
void matrix3::linie()
{
cout << "test is\n";
cout << "\n Numerele coloanelor care doriti sa le interschimbati";
cout << "\n l1: ";cin >> l1;
cout << "\n l2: ";cin >> l2;
for (i = 1; i <= x; i++)
{
save = a[l1][j];
a[l1][j] = a[l2][j];
a[l2][j] = save;
}
for (i = 1;i <= x;i++) {
for (j = 1;j <= y;j++) {
cout << a[i][j] << " ";
}
cout << endl;
}
}
void matrix3::minimul_elementelor_pare()
{
cout << "Minimul Elementelor Pare";
for (i = 1;i <= x;i++)
{
if (x % 2 == 0)
{
if (a[i][j] < min)
min = a[i][j];
}
min++;
}
cout << " " << min;
}
void matrix3::maximul_elementelor_prime()
{
cout << "max matrice" << endl;
max=a[1][1];
for (i = 1;i <= x/2;i++)
{
for (j = 1;j <= y/2;j++)
if (x%i != 0 && max < a[i][j])
max = a[i][j];
}
cout << " maximul din matrice este " << max;
}
int main()
{
int input;
char ch;
matrix3 m;
m.values();
do
{
cout << "Enter your choice\n";
cout << " 1. Sum of 1 and 2\n" << " 2. Difference of 1 and 2\n" << " 3. Transpose of both 1 amd 2\n" << "4. Linii\n" << "5. Minim\n" << "6.Linie\n"<<"7. Maxim\n";
cin >> input;
switch (input)
{
case 1:
m.sum();
break;
case 2:
m.diff();
break;
case 3:
m.transpose();
break;
case 4:
m.coloana();
break;
case 5:
m.coloana();
break;
case 6:
m.minimul_elementelor_pare();
break;
case 7:
m.maximul_elementelor_prime();
}
cout << "\nDo another y/n?\n";
cin >> ch;
} while (ch != 'n');
cout << "\n";
system("pause");
return 0;
}```

algorithm - merging similar lines into one

I am using the Hough transform algorithm do determine lines.
Right now I am just taking the peak values from the matrix that are over a certain threshold, but I am getting a lot of duplicate lines that i want to merge into one.
This is the code for finding peaks:
int prevVal = INT_MIN;
const int NOISE = 110;
enum
{
Ascending,
Descending
} direction = Ascending;
std::vector<Peak>peaks;
for (int x = 0; x < m_matrixWidth - 1; x++) {
for (int y = 0; y < m_matrixHeight - 1; y++) {
double currentValue = m_matrix[x*m_matrixHeight + y];
if (prevVal < currentValue) {
direction = Ascending;
}
else if (prevVal > currentValue) {
if (direction != Descending) {
if (currentValue > NOISE) {
Peak peak(x, y, currentValue);
peaks.push_back(peak);
std::cout << "peak at index " << x*m_matrixHeight + y << ": " << prevVal << std::endl;
}
direction = Descending;
}
}
prevVal = currentValue;
}
}
return peaks;
This is how it looks:
If anyone knows, thanks.

Runtime Error in CodeForces

I am trying to solve this problem : http://codeforces.com/contest/664/problem/B
Here is my code : http://ideone.com/fWgQEn
I am getting Runtime Error on Test Case 5, even though my answer is correct and I am printing it properly.
Can anyone tell me what could be the reason of this?
#include<bits/stdc++.h>
using namespace std;
int main(){
int i = 0, pos = 1, neg = 0, n;
string str;
char x;
while(1){
cin >> x;
if(x == '=') break;
else if (x == '?') continue;
else if (x == '+') pos++;
else if (x == '-') neg++;
str[i++] = x;
}
str[i] = '\0';
// cout << str[0] << str[1] << str.size() << endl;
cin >> n;
if (!(pos * n - neg >= n && pos - neg * n <= n))
cout << "Impossible" << endl;
else{
cout << "Possible\n";
int neg_sum, pos_sum;
for (int i = neg; i <= neg * n; i++){
pos_sum = n + i;
if(pos_sum <= pos * n && pos_sum >= pos) {
neg_sum = i; pos_sum = n + i;
break;
}
}
// cout << str.size() << endl;
// cout << pos_sum << " " << neg_sum << endl;
int pos_count = 1, neg_count = 0;
for(int i = -1 ; i < pos + neg - 1; i++){
// cout << "i " << i << " " << str[i] <<endl;
if(!(i + 1)){
if(pos == 1) cout << pos_sum << " ";
else cout << pos_sum / (pos - 1) << " ";
}
else{
if(str[i] == '+'){
if(pos_count++ != pos -1) cout << "+ "<< pos_sum / (pos - 1) << " ";
else cout << "+ "<< pos_sum % (pos - 1) << " ";
}
else{
if(neg == 1) cout << "- " << neg_sum << " ";
else if(neg_count++ != neg -1) cout << "- "<< neg_sum / (neg - 1) << " ";
else cout << "+ "<< neg_sum % (neg - 1) << " ";
}
}
}
cout << "= " << n;
}
return 0;
}
TIA!!
string str;
char x;
while(1){
cin >> x;
if(x == '=') break;
else if (x == '?') continue;
else if (x == '+') pos++;
else if (x == '-') neg++;
str[i++] = x;
}
I think at least str[i++] = x; will run into un-allocated spaces and cause undefined behavior. See
http://www.cplusplus.com/reference/string/string/operator[]/
Try
str += x; i++;
instead.

opencv3.1 by uchar to int

I have this code where I have to edit the works of M with 2 values ​​when required .
Mat is a distance given by distancetrasform . If I try to start facciene release me so I do not how I want the value int 2 . I tried to cast but nothing . How do I change the pixel values ​​of M ? with int value ?
Mat M = Mat::zeros(300, 300, CV_8U);
int i, j;
for (i = 0; i < distanza.cols ; i++)
{
for (j = 0; j < distanza.rows ; j++)
{
if ((int)distanza.at<float>(i,j) > 0 )
{
M.at <uchar>(i,j) = 2 ; //here as i write ?
cout << " " << M.at <uchar>(i, j) << endl;
}
}
}

Resources