How to set the "pcl::PointIndices" with the PCD file (existing point cloud sets) - point-cloud-library

I'm trying to implement a pointcloud background subtraction.
(eg. background.pcd = input.pcd - object.pcd)
I found following code
pcl::PointCloud<pcl::PointXYZ>::Ptr p_obstacles(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointIndices::Ptr inliers(new pcl::PointIndices());
pcl::ExtractIndices<pcl::PointXYZ> extract;
// Insert something.
extract.setInputCloud(p_obstacles);
extract.setIndices(inliers);
extract.setNegative(true);
extract.filter(*p_obstacles);
Removing points from a pcl::PointCloud<pcl::PointXYZRGB>
In my understating, the inliers is subtracted from the input.pcd
(inliers = object.pcd ??)
I have no idea how to set the inliers value with the pre-existing x,y,z values(pcd)
Thank you!

There's a getIndices() method in the PCLBase class: http://docs.pointclouds.org/1.8.1/classpcl_1_1_p_c_l_base.html#a058753dd4de73d3d0062fe2e452fba3c
Here's how to use it:
pcl::PCLBase<pcl::PointXYZ> base; // Instantiate the PCLBase class
base.setInputCloud(object_cloud); // Set input cloud before grabbing the indices
auto object_indices = base.getIndices();
extract.setIndices(object_indices);
You might need to include the header file
#include <pcl/pcl_base.h>
And if you haven't created a point cloud from your pcd file, you can follow this tutorial:
http://pointclouds.org/documentation/tutorials/reading_pcd.php

Related

Trying to create point from X,Y, coordinate

I have used a formula to create an X and Y coordinate that I would like to create a point from. They are held in the attribute table, and I don't know how to use those points for the geometry. Here's the code:
cursor01 = arcpy.da.InsertCursor(OutPutCent,["SHAPE#X", "SHAPE#Y","Xcoord","Ycoord","totpop", "NAME","STATE_NAME","POLY_ID", "OBJECTID", "STATE_FIPS", "CNTY_FIPS", "FIPS", "FIPSnum","FIPS_NUMER" ])
#if row[0] >= 5.2:
cursor01.insertRow([XPoint,YPoint,centroid_X1,centroid_Y1,TotalPop1,thecntyName1,TheStateName1,idpoly1, idobject1, stateFIPS1, countyFIPS1, fips1, fipSnum1, fipsNumer1])
Any suggestions would be much appreciated I need to resolve this asap!
Best
This should probably be in gis.stackexchange.com.
Hard to tell what you're aiming for with that code, but I'll have a guess anyway...If you have existing points you want to relocate based on updated coordinates in an attribute table, try one of the following.
The simple no-scripting solution is this:
export your attribute table to csv
use Add XY Data to import the csv as a new layer
During the import process you can set the geometry to your Xcoord, Ycoord attribute fields, so the new dataset will have updated locations. Then just prune any records you don't want - looks like you're filtering on some value? Select by Attributes and delete rows that don't meet your condition.
Alternatively, a structurally correct template to update existing geometry with new coordinates from the attibute table is:
with arcpy.da.UpdateCursor(dataset, ['SHAPE#XY', 'point_unique_id_or_name', 'conditional_field', 'X_coord', 'Y_coord']) as cursor:
update_count = 0
for row in cursor:
if row[conditional_field_index] meets condition:
updated_point = (row[X_coord_index], row[Y_coord_index])
row[SHAPE#XY_index] = updated_point
cursor.updateRow(row)
print "{} location updated".format(row[point_unique_id_or_name_index])
update_count += 1
print "{} point locations updated".format(update_count)
You only need to reference relevant fields in the UpdateCursor - if they don't get referenced inside the for loop, don't include them.
Strongly advise you practice on a copy of your original dataset.
you need to import QPoint from QtCore:
from PyQt5.QtCore import QPoint
Then create a qpoint object:
_qpoint = QPoint()
Then add your desired x and y coordinates with the setX, and setY methods:
_qpoint.setX()
_qpoint.setY()
example:
_qpoint.setX(500)
_qpoint.setY(700)
beware of the capital X and Y in the 'set' method of the point object.
For more details, refer to this link.

Set caffe net parameters via string

What I want to do is the following:
I encrypted the ".prototxt" and ".caffemodel" file, so the files are not readable and the parameters not visible. During my program I decrypt the file and store the result as a string. But now I need to set the layers in my caffe network.
Is there a method to set the caffe network layers with the parameters from my string? Same for the layers in the trained network? Something comparable with the source code below (I know this source code would not work)?
shared_ptr<Net<float> > net_;
string modelString;
string trainedString;
//Decryption stuff
net_.reset(new Net<float>(modelString, TEST));
net_->CopyTrainedLayersFrom(trainedString);
Thank you a lot.
You could initialize a NetParameter class directly using the Protocol Buffer API of the NetParameter class (you'll need to include caffe/proto/caffe.pb.h):
bool ParseFromString(const string& data);
and then use it to initialize a Net class using the following constructor:
explicit Net(const NetParameter& param, const Net* root_net = NULL);
and for copying the weights:
void CopyTrainedLayersFrom(const NetParameter& param);
It's important to note that the above method requires that the string variable contains binary-formatted protobuffer and not the text-format. While the caffemodel outputted by Caffe is already in binary format, you'll have to convert the prototxt file to binary format as well, but you could do that using the protoc command-line program combined with the --encode flag.
For a more information, I'd suggest you'll look in the Protocol-Buffer's website: https://developers.google.com/protocol-buffers/
Loading net model from text format (without converting with protoc) can be done by following:
#include <google/protobuf/text_format.h>
// [...]
NetParameter net_parameter;
bool success = google::protobuf::TextFormat::ParseFromString(model, &net_parameter);
if (success){
net_parameter.mutable_state()->set_phase(TEST);
net_.reset(new Net<float>(net_parameter));
}

Sending vector data in the bus

I have a vector data (an array variable for example float32 mydata[5];). for transmitting a single primitve/basic data in a bus its pretty simple.
inside_data=Simulink.BusElement;
inside_data.Name='somename';
inside_data.SampleTime = -1;
inside_data.datatype='single';
this element can be put inside a using
Bus=Simulink.Bus;
Bus.Elements=inside_data;
But this works when the input is a primitive. But what if my data is a vector. like float32 a[5]; then how can i send this data element in a bus.
UPDATE
So I tried to use a constant block named a with datatype single in which the input part i changed it as [1 2 3] which is a vector input.
another element is b with uint8 datatype.
i used the s-function builder just to check the working of this model. i already set everything (bus_mode on , datatype to be bus type etc). in the output part i used something like:
y0[0]=u0->a[0];
y0[1]=u0->a[1];
y0[2]=u0->a[2];
y1[0]=u0->b;
But it throws error as
c:\program files (x86)\matlab_v7111_r10bsp1\extern\include\matrix.h(313) : error C2061: syntax error : identifier 'mxLogical'
c:\program files (x86)\matlab_v7111_r10bsp1\extern\include\matrix.h(313) : error C2059: syntax error : ';'
my final aim is to use it for s_function
so if i declare a variable in s_func as
real32_T *a_output[5]=(real32_T *)ssGetOutputPortRealSignal(S,0);
and then i have a strcuture(because am transmitting data with a bus so the bus header file has this structure) and how do i declare and assign the input to the output.
a_output[0]=my_struct->a_input[0];
a_output[1]=my_struct->a_input[1];
a_output[2]=my_struct->a_input[2];
a_output[3]=my_struct->a_input[3];
a_output[4]=my_struct->a_input[4];
but the problem is with the declaration. it gives me error cannot convert from real32_T to real32_T * .
The main idea is to create Bus of type you need.
I did it this way:
num = zeros(15,15,15);
move = zeros(15,15,15);
a = struct('number',num,'movement', move);
busInfo = Simulink.Bus.createObject(a);
You can see it's possible to create any data structure, array, vector anything you want and then create Bus Signal of the same type.
I use this in callbacks/preLoadFcn (Model Explorer) to define this type in workspace, it creates slBus1 variable (its Bus Signal of my type), so I need to define output (or input if necessary) of any block like slBus1 only. And then use Bus Selector to work array data.
Can it helps to you?
ADD NEW INFORMATION
It depends of what you want.
For example: I create s-function for feedback system. It use my structure like this:
function a = fcn(BusSignal)
%#codegen
num = zeros(15,15,15);
move = zeros(15,15,15);
%...some math actions with num and move...
a = struct('number',num,'movement', move);
%...and some action with a structure... for example:
if (c>b)
a.number(1,2,3) = 15;
a.movement(1,2,3) = 42;
else
a = BusSignal;
end
Look at this - I use Bus signal at entrance and at exit and use Bus Selector to work it's data with.
REMEMBER to define input and output data as Bus Signals!

Convert WebMercatorExtent in Extent in Flex

I retrieve dynamically an Array with latidude longitude values that need to be calculated into an Extent so they fit exactly on a map (Adobe Flex). The layers I'm using in the Esri Map component are now:
<esri:ArcGISTiledMapServiceLayer id="arcgisonlineLayer" load="{trace(arcgisonlineLayer.version)}"
url="http://services.arcgisonline.nl/arcgis/rest/services/Basiskaarten/PDOK_BRT/MapServer"/>
<esri:WMSLayer url="{wmsLayerUrl}">
<esri:visibleLayers>
<s:ArrayList>
<fx:String>0</fx:String><!-- background colors -->
<fx:String>1</fx:String><!-- signs -->
<fx:String>2</fx:String><!-- red overview road map can be outcommented-->
<fx:String>3</fx:String><!-- lines -->
</s:ArrayList>
</esri:visibleLayers>
</esri:WMSLayer>
Before I used the standard Esri layers...
<esri:ArcGISTiledMapServiceLayer id="serviceLayer"
url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"
visible="{viewModeButtonBar.selectedIndex == 0}"/>
<esri:ArcGISTiledMapServiceLayer
url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"
visible="{viewModeButtonBar.selectedIndex == 1}"/>
..and I could use the WebMercatorExtent class to create an extend that would fit but now I need to use these layers and can't use the WebMercatorExtent because the service "http://services.arcgisonline.nl/arcgis/rest/services/Basiskaarten/PDOK_BRT/MapServer" uses
<esri:SpatialReference id="wgs" wkid="28992"/>
Which doesn't go with WebMercatorExtent. Anyone knows how to convert this com.esri.ags.geometry.WebMercatorExtent into an Extent?
It sounds like you need to convert a longitude/latitude Extent to an Extent in spatial reference 28992, right? If so, see the Flex sample on projecting geometries. Especially see the projectNow function. It uses GeometryService.project to project points from one coordinate system to another. You can use the same function to project extents from one coordinate system to another.
Here is how it's done in code. You need to declare as GeometryService that uses some an external webservice. This one is the sampleservice from Esri that might be out of order when you read this answer because there has been an upgrade. Best is to use your own arcgis service, for now I used this one:
http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer
Put in to Declarations
<fx:Declarations>
<esri:GeometryService id="geometryService"
concurrency="last"
fault="geometryService_faultHandler(event)"
projectComplete="projectCompleteHandler(event)"
showBusyCursor="true"
url="http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer"/>
</fx:Declarations>
Then create the WebMercatorExtent, create a SpatialReference you want your Geometry converted to and project it. The web service will provide the answer...
var wmExtent:WebMercatorExtent = new WebMercatorExtent(
_mapItemBounds.getSouthWest().lng(),
_mapItemBounds.getSouthWest().lat(),
_mapItemBounds.getNorthEast().lng(),
_mapItemBounds.getNorthEast().lat());
var outSR:SpatialReference = new SpatialReference(28992);
const projectParameters:ProjectParameters = new ProjectParameters;
projectParameters.geometries = [ wmExtent];
projectParameters.outSpatialReference = outSR;
geometryService.project(projectParameters);
...in the function
protected function projectCompleteHandler(event:GeometryServiceEvent):void
{
try
{
// Note: As of version 2.0, GeometryService returns geometries (instead of graphics)
var extent:Extent = (event.result as Array)[0] as Extent;
map.extent = extent;
}
catch (error:Error)
{
Alert.show(error.toString());
}
}

Reading DICOM 1.2.840.10008.1.2.4.70

I have a problem when reading DICOM file. This is the format 1.2.840.10008.1.2.4.70(Process 14 with a first-order prediction (Selection Value 1). I write my own software.
Here is result of my work.
I also give you a .dcm file.
What can be wrong with it? Only RadiAnt Dicom Viewer open it corectly ( i didn't find any working software with source code ).
Have someone any tutorial about it? Any working code?
I'll be very grateful!
Thanks for help.
I show you how I it do:
//I have:
numCOL= imageWidth;
numROW= imageHeight;
dwCurrentBufferLength;//-> where I in file
//and other stuff...
//First i decode first row:
//[0][0]
DecodeFirstRow(curRowBuf,dwCurrentBufferLength);
//I calculate difrences
HuffDecode ( table , &val, dwCurrentBufferLength);
//and extend
HuffExtend(extend, val);
curRowBuf[0][curComp]=extend+(1<<(Pr-Pt-1));
//[1-n][0]
//... huff stuff
curRowBuf[col][curComp]=extend+curRowBuf[col-1][curComp];
//Then i put row to the vector:
for (col = 0; col < numCol; col++)
{
v=RowBuf[col][0]<<point_transform_parameter;
m_vOutputBuf.push_back(v);
}
//Rest of columns
//[0][m]
curRowBuf[0][curComp]=extend+prevRowBuf[0][curComp];
predictor = left =curRowBuf[leftcol][curComp];
//[1-n][m]
curRowBuf[col][curComp]=extend+predictor;
//and also put it to vector ^^
Where i must sub this 1000??
Most likely you have not accounted for the Rescale Intercept, tag (0028,1052) when calculating your HU values. According to the DICOM file, the intercept is -1000.
To get the appropriate HU values of your image, use this formula:
HU = rescale_slope * pixel_value + rescale_intercept
where Rescale Intercept is thus obtained from tag (0028,1052) and Rescale Slope from tag (0028,1053).
Here is what I see using gdcmviewer:
$ gdcmviewer 3DSlice1.dcm
GDCM is open source you could study it.

Resources