sorry to bother. Could you know maybe how can i fix my code. It gives me this error:
/usr/include/eigen3/Eigen/src/Core/DenseCoeffsBase.h:365: Eigen::DenseCoeffsBase<Derived, 1>::Scalar& Eigen::DenseCoeffsBase<Derived, 1>::operator()(Eigen::Index, Eigen::Index) [with Derived = Eigen::Matrix<float, -1, -1>; Eigen::DenseCoeffsBase<Derived, 1>::Scalar = float; Eigen::Index = long int]: Assertion `row >= 0 && row < rows() && col >= 0 && col < cols()' failed.
I think that I declared matrix in right way. My mistake (I think) is when i try to fill her with values in Possible transforms function. I think it might be wrong transform1(0, position)=.. I tried it to comment that lines of code and wrote a simple code like transform1(0, position)=1; and it gave the same error.
Sorry to bother,
Kind regards.
My code :
#include "ros/ros.h"
#include <cstdlib>
#include <fstream>
#include <stdio.h>
#include <regex>
#include "sensor_msgs/PointCloud2.h"
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_types.h>
#include <pcl/PCLPointCloud2.h>
#include <pcl/conversions.h>
#include <pcl_ros/transforms.h>
#include <boost/shared_ptr.hpp>
#include "pcl_ros/point_cloud.h"
#include "sensor_msgs/PointField.h"
#include <pcl/io/pcd_io.h>
#include "nav_msgs/Odometry.h"
#include "eigen3/Eigen/SVD"
#include "eigen3/Eigen/Dense"
#include "clustering/Track.h"
#include "eigen3/Eigen/Core"
#include "eigen3/Eigen/Sparse"
using namespace Eigen;
int number_od_possible_tracks = 15;
class Odometry_class {
ros::NodeHandle nodeh;
ros::Subscriber sub;
ros::Publisher pub;
public:
Odometry_class();
void Odometry(const sensor_msgs::PointCloud2 &msg);
bool Has_pointcloud_min3points(pcl::PointCloud<pcl::PointXYZIVSI> cloud);
bool Possible_transform(pcl::PointCloud<pcl::PointXYZIVSI> cloud);
void Restore_Ids();
pcl::PointCloud<pcl::PointXYZIVSI> last_cloud;
Eigen::MatrixXf transform1 = (Eigen::MatrixXf(3,15));
Eigen::MatrixXf transform2=(Eigen::MatrixXf(3,15));
int consecutive_Ids_current[15];
int consecutive_Ids_previous[15];
int position;
void Transform();
};
Odometry_class::Odometry_class(){
sub = nodeh.subscribe("trackers", 10, &Odometry_class::Odometry, this);
pub = nodeh.advertise<nav_msgs::Odometry>("odometry", 10);
}
void Odometry_class::Odometry(const sensor_msgs::PointCloud2 &msg ){
pcl::PCLPointCloud2 pcl_pc2;
pcl_conversions::toPCL(msg, pcl_pc2);
pcl::PointCloud<pcl::PointXYZIVSI> cloud;
pcl::fromPCLPointCloud2(pcl_pc2, cloud);
if(Possible_transform(cloud)){
ROS_INFO("Transformation is possible");
}
else{
ROS_INFO("Transformation is not possible");
}
Restore_Ids();
pcl::fromPCLPointCloud2(pcl_pc2, last_cloud);
}
void Odometry_class::Restore_Ids(){
int i=0;
while(consecutive_Ids_current[i]!=0){
consecutive_Ids_current[i]=0;
consecutive_Ids_previous[i]=0;
i++;
}
}
bool Odometry_class::Has_pointcloud_min3points(pcl::PointCloud<pcl::PointXYZIVSI> cloud){
bool has=false;
if(cloud.width>=3){
has=true;
}
return has;
}
bool Odometry_class::Possible_transform(pcl::PointCloud<pcl::PointXYZIVSI> cloud){
bool possible=false;
position=0;
if(Has_pointcloud_min3points(cloud)&Has_pointcloud_min3points(last_cloud)){
for(int i=0;i<cloud.width;i++){
for(int j=0;j<last_cloud.width;j++){
if(cloud[i].id==last_cloud[j].id){
consecutive_Ids_current[position]=i;
consecutive_Ids_previous[position]=j;
position++;
}
}
}
}
if(position>=3){
possible=true;
transform1.resize(3,position);
transform2.resize(3,position);
for(int i=0;i<position;i++){
transform1(0,position)= cloud[consecutive_Ids_current[i]].x;
transform1(1,position)= cloud[consecutive_Ids_current[i]].y;
transform1(2,position)= cloud[consecutive_Ids_current[i]].z;
transform2(0,position)= cloud[consecutive_Ids_previous[i]].x;
transform2(1,position)= cloud[consecutive_Ids_previous[i]].y;
transform2(2,position)= cloud[consecutive_Ids_previous[i]].z;
}
}
return possible;
}
int main(int argc, char **argv) {
ros::init(argc, argv, "Odometry");
Odometry_class Odometry;
ros::spin();
return 0;
}
I think you mixed up your loop variable, i, and upper limit, position. Using position as an index would result in accessing the matrix out of bounds, and the Eigen library catches that in an assertion. Using the loop variable should resolve the error.
transform1(0,i)= cloud[consecutive_Ids_current[i]].x;
And likewise for the rest of the transform1 and transform2 assignments.
Related
I have a code that is executable without error messages but it seems like it denies to run the code
I call by the "spawnl" command. This is my code and I receive "error=-1". I tried may different ways to solve the situation but I always receive the "-1" for an answer. I use Dev C++ compiler with 32bit release. My problem is to call the other program, sending the name of the file.
#include <stdlib.h>
#include <graphics.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <conio.h>
#include <process.h>
#include <ctype.h>
#include <dir.h>
#include <windows.h>
#include <dos.h>
#include <iostream>
#include <stddef.h>
void translate_to_ascii_files(),
save_mesh_data(),
make_no(),
give_names();
int load_patches(char *);
FILE *memco ;
int outnod[400] ;
float r_vector[21][21][3],cx[500],cy[500],cz[500] ;
int NOP1,NOP2; /* Number Of Points */
int patches;
char nams[26][26];
int num_of_files;
int kk,nv,nh,exnod,totnod ;
int no[4][400];
char filename[26];
void *buf;
COORD coord= {0,0};
HANDLE hConsole;
using namespace std; // std::cout, std::cin
void gotoxy(int x,int y) {
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
int main(int argc,char *argv[]) {
char com_nam[26];
int counter1,counter2,i;
int error;
system("cls");
give_names();
printf("give the final filename:");scanf("%s",filename);
for(patches=1;patches<=num_of_files;patches++) {
strcpy(com_nam,nams[patches]);
load_patches(com_nam); /* load patches for meshing*/
i=1;
for(counter1=0;counter1<=NOP1;counter1++) {
for(counter2=0;counter2<=NOP2;counter2++) {
cx[i]=r_vector[counter1][counter2][0];
cy[i]=r_vector[counter1][counter2][1];
cz[i]=r_vector[counter1][counter2][2];
i=i+1;
}
}
nh=NOP1+1;nv=NOP2+1;
make_no();
save_mesh_data();
if(argc ==1){
error=spawnl(P_WAIT,"c:\\cpprog\\unitsrf.exe","",filename,NULL);
if (error ==0) {
else {printf ("error=%d\n",error); system("PAUSE");
} }
else{gotoxy(2,11);printf("error=%s\n\n",argv[1]);
system("PAUSE");
}
} translate_to_ascii_files();
}
I have written the code to access opencv(Mainly used for image processing) function from Scilab(numerical computation software). When I run bilder gateway file, I am encountering below error.
opencv_NormalizeHist.cpp:47:34: error: 'NormalizeHist' was not declared in this scope.
#include <numeric>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace cv;
using namespace std;
extern "C"
{
#include "api_scilab.h"
#include "Scierror.h"
#include "BOOL.h"
#include <localization.h>
#include "../common.h"
int opencv_NormalizeHist(char *fname, unsigned long fname_len)
{
SciErr sciErr;
int iRows=0,iCols=0;
int *piAddr2 = NULL;
//checking input argument
CheckInputArgument(pvApiCtx, 2, 2);
CheckOutputArgument(pvApiCtx, 0, 0) ;
//Define histogram
Mat hist;
retrieveImage(hist,1);
double *factor;
//for value of factor
sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRows, &iCols ,&factor);
if(sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
NormalizeHist(hist, factor[0]); //Normalizing hist
string tempstring = type2str(hist.type());
char *checker;`enter code herek
checker = (char *)malloc(tempstring.size() + 1);
memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
returnImage(checker,hist,1); //here, remove the temp as a parameter as it is not needed, and instead add 1 as the third parameter. 1 denotes that the first output argument will be this variable
free(checker); //free memory taken up by checker, i missed this earlier
//Assigning the list as the Output Variable
AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
//Returning the Output Variables as arguments to the Scilab environment
ReturnArguments(pvApiCtx);
return 0;
}
/* ==================================================================== */
}
Getting Type expression list treated as compound expression in initializer
On both these function calls -
char itoa(new_total, new_total_ch, 10);
int setenv("COUNT_TOTAL", new_total_ch, 1);
Here's the code snippet -
#include <iostream>
// create process team
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <ctime>
// initialize & process
#include <time.h>
#include <string>
#include <fstream>
#include <cmath>
#include <iosfwd>
// initialize & process
using std::ifstream;
using namespace std;
class Count3sProcessParallel {
public:
//int process();
int pr_count;
int process();
typedef int COUNT_TOTAL;
private:
int worker;
//declare process()
long unit_of_work;
long lower_bound;
long upper_bound;
int pr_i;
char * ct;
int ct_i;
int new_total;
char itoa();
char * new_total_ch;
int setenv();
};
int Count3sProcessParallel::process() {
// determine upper lower bounds
unit_of_work = in_length/workers_num;
lower_bound = (worker -1) * unit_of_work;
upper_bound = (worker * unit_of_work) -1;
// iterate and count
pr_count = 0;
for (pr_i = lower_bound; pr_i < upper_bound; pr_i++)
if (floor(in_buffer[pr_i] == 3))
pr_count++;
return pr_count;
//update COUNT_TOTAL
ct = getenv("COUNT_TOTAL");
ct_i = atoi(ct);
new_total = (pr_count + ct_i);
char * new_total_ch[33];
char itoa(new_total, new_total_ch, 10);
int setenv("COUNT_TOTAL", new_total_ch, 1);
delete[] in_buffer;
return 0;
}
How do I resolve this? Thanks.
Remove the leading types. Just use:
itoa(new_total, new_total_ch, 10);
setenv("COUNT_TOTAL", new_total_ch, 1);
I want to create some modules for my program. I want to call a function and pass a vector as a parameter. The return value should also be a vector.
My code looks like this
main.cpp
//BlueSmart.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
#include "stdafx.h"
#define WIN32_LEAN_AND_MEAN
using namespace std;
#pragma comment(lib, "Irprops.lib")
BLUETOOTH_FIND_RADIO_PARAMS m_bt_find_radio = {
sizeof(BLUETOOTH_FIND_RADIO_PARAMS)
};
BLUETOOTH_RADIO_INFO m_bt_info = {
sizeof(BLUETOOTH_RADIO_INFO),
0,
};
BLUETOOTH_DEVICE_SEARCH_PARAMS m_search_params = {
sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS),
1,
0,
1,
1,
1,
15,
NULL
};
BLUETOOTH_DEVICE_INFO m_device_info = {
sizeof(BLUETOOTH_DEVICE_INFO),
0,
};
HANDLE m_radio = NULL;
HBLUETOOTH_RADIO_FIND m_bt = NULL;
HBLUETOOTH_DEVICE_FIND m_bt_dev = NULL;
int wmain(int argc, wchar_t **args) {
while(true) {
m_bt = BluetoothFindFirstRadio(&m_bt_find_radio, &m_radio);
do {
localBluetoothDevices ();
m_search_params.hRadio = m_radio;
::ZeroMemory(&m_device_info, sizeof(BLUETOOTH_DEVICE_INFO));
m_device_info.dwSize = sizeof(BLUETOOTH_DEVICE_INFO);
m_bt_dev = BluetoothFindFirstDevice(&m_search_params, &m_device_info);
vector<wstring> vec;
int m_device_id = 0;
do {
wostringstream tmp;
++m_device_id;
//Something like this <----------------------------------------
externBluetoothDevices (vec);
//Something like this <----------------------------------------
wprintf(L"********************************************************************** \n");
wprintf(L"\tDevice %d:\r\n", m_device_id);
wprintf(L"\t\tName: %s\r\n", m_device_info.szName);
wprintf(L"\t\tAddress: %02x:%02x:%02x:%02x:%02x:%02x\r\n", m_device_info.Address.rgBytes[0], m_device_info.Address.rgBytes[1], m_device_info.Address.rgBytes[2], m_device_info.Address.rgBytes[3], m_device_info.Address.rgBytes[4], m_device_info.Address.rgBytes[5]);
wprintf(L"====================================================================== \n");
for (int i = 0; i < 6; i++) {
tmp << hex << m_device_info.Address.rgBytes [i];
if (i < 5)
tmp << L':';
}
vec.push_back(tmp.str());
} while(BluetoothFindNextDevice(m_bt_dev, &m_device_info));
BluetoothFindDeviceClose(m_bt_dev);
//Sleep(10*1000*60);
Sleep(10000);
} while(BluetoothFindNextRadio(&m_bt_find_radio, &m_radio));
BluetoothFindRadioClose(m_bt);
}
return 0;
}
//Lokal verfügbare bzw. angeschlossene Bluetooth-Devices
void localBluetoothDevices (){
int m_radio_id = 0;
m_radio_id++;
BluetoothGetRadioInfo(m_radio, &m_bt_info);
//Lokaler Bluetoothadapter
wprintf(L"====================================================================== \n");
wprintf(L"Local Device Nr. %d\n", m_radio_id);
wprintf(L"\tName: %s\r\n", m_bt_info.szName);
wprintf(L"\tAddress: %02x:%02x:%02x:%02x:%02x:%02x\r\n", m_bt_info.address.rgBytes[0], m_bt_info.address.rgBytes[1], m_bt_info.address.rgBytes[2], m_bt_info.address.rgBytes[3], m_bt_info.address.rgBytes[4], m_bt_info.address.rgBytes[5]);
}
//Extern verfügbare bzw. Bluetooth-Devices
vector<wstring> externBluetoothDevices (vector<wstring> &vec){
return vec;
}
stdafx.h
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <winsock2.h>
#include <windows.h>
#include <stdlib.h>
#include <bthdef.h>
#include <BluetoothAPIs.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <iomanip>
#include <conio.h>
void localBluetoothDevices ();
vector<wstring> externBluetoothDevices (vector<wstring>);
It says that vector is not a known type. What am I doing wrong?
In stdafx.h replace
vector<wstring> externBluetoothDevices (vector<wstring>);
with
std::vector<std::wstring> externBluetoothDevices (std::vector<std::wstring>);
Basically the issue was although you put using namespace std; in your cpp file that doesn't count in your header file which is before the using declaration is seen.
Also note that your defintion in the cpp file is different. In the cpp file you have a reference
vector<wstring> externBluetoothDevices (vector<wstring>&);
Decide which you really want.
You should pass a pointer of a vector.
I have a problem with the code OpenKinect provides. I'm trying to use the Kinect with c++, but I get this error. On the web this question was already asked, but I have not find a decent answer. The code is this:
#include <cstdlib>
#include "libfreenect.h"
#include "libfreenect.hpp"
#include <pthread.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <cmath>
#include <vector>
#if defined(__APPLE__)
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#endif
using namespace std;
class Mutex {
...
};
class MyFreenectDevice : public Freenect::FreenectDevice {
public:
MyFreenectDevice(freenect_context *_ctx, int _index)
: Freenect::FreenectDevice(_ctx, _index),
m_buffer_depth(freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB).bytes),
m_buffer_video(freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB).bytes),
m_gamma(2048),
m_new_rgb_frame(false),
m_new_depth_frame(false)
{
for (unsigned int i = 0; i < 2048; i++) {
float v = i / 2048.0;
v = std::pow(v, 3) * 6;
m_gamma[i] = v * 6 * 256;
}
}
...
private:
std::vector<uint8_t> m_buffer_depth;
std::vector<uint8_t> m_buffer_video;
std::vector<uint16_t> m_gamma;
Mutex m_rgb_mutex;
Mutex m_depth_mutex;
bool m_new_rgb_frame;
bool m_new_depth_frame;
};
Freenect::Freenect freenect;
MyFreenectDevice* device;
freenect_video_format requested_format(FREENECT_VIDEO_RGB);
...
I get the error Unable to resolve identifier identifier freenect for the instruction Freenect::Freenect freenect;.
The code of this template is in the libfreenect.hpp code:
class Freenect : Noncopyable {
private:
typedef std::map<int, FreenectDevice*> DeviceMap;
public:
...
template <typename ConcreteDevice>
ConcreteDevice& createDevice(int _index) {
DeviceMap::iterator it = m_devices.find(_index);
if (it != m_devices.end()) delete it->second;
ConcreteDevice * device = new ConcreteDevice(m_ctx, _index);
m_devices.insert(std::make_pair<int, FreenectDevice*>(_index, device));
return *device;
}
...
}
I have no idea of what is the problem, this is the official code and it should work.. any suggestions? thanks in advance