Point Cloud Visualization - point-cloud-library

I am trying to load and visualize a point cloud data by "addPointCloud" instruction.
//***********
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);
if (pcl::io::loadPCDFile<pcl::PointXYZRGBA> ("f.pcd", *cloud) == -1)
{
PCL_ERROR ("Couldn't read the pcd file \n");
return (-1);
}
pcl::visualization::PCLVisualizer viewer ("Simple Cloud Viewer");
viewer.setBackgroundColor (0, 0, 0);
viewer.addPointCloud(cloud, "sample cloud");
//***********
But instead of seeing my point cloud in a black background, only see a white backbround whithout any point cloud. Can any one tell me kindly where is my problem?

add the following to your code
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
// do stuff
pcl::visualization::PointCloudColorHandlerRGB<pcl::PointXYZRGB> rgb(cloud);
viewer.addPointCloud <pcl:PointXYZRGB> (cloud,rgb,"cloud1");
Depending on the viewpoint you have to zoom out.
Hope this helps

pcl::visualization::PCLVisualizer viewer window object has been created and you're currently looking at just the window... You would need to add .spin()
viewer.spin();

Related

Launch MAP in Xamarin Forms ANDROID and camera move to user's current location

all right?
I'm banging my head with something that might be simple, but I can't think of anything else.
I want to make it so that when the user opens my app's map screen, the map camera will focus on where the user is located in real time.
PS: I'm using Xamarin.Essentials
Ps2: With this code the camera stays at Rome city or moves to ocean, but i need that moves to my atual position.
Below is the code I'm using, any help is welcome.
public async void AproximaLocalUsuario()
{
try
{
var request = new GeolocationRequest(GeolocationAccuracy.Medium);
var location = await Geolocation.GetLocationAsync(request);
if (location != null)
{
Position position = new Position(location.Latitude, location.Longitude);
MapSpan mapSpan = MapSpan.FromCenterAndRadius(position, Distance.FromKilometers(0.444));
map.MoveToRegion(mapSpan);
}
}
catch (FeatureNotSupportedException fnsEx)
{
// Handle not supported on device exception
}
I managed to get it to work, I wasn't starting the function, that was the problem. Below is the code that is working for me. Thanks for your help and I hope this post helps more people.

MapsUI always shows "own location" marker at LatLng 0,0

I have the issue with MapsUI 2.0.3 that the marker of my own location is always at 0,0 west of Africa. Clicking the focus on own location button obviously also moves me there.
I did add coarse and fine location permissions to manifest and do get permission to access locations, but "you are here" is always 0,0.
I then downloaded the MapsUI repository, and tried the samples, which show the same behavior, mostly. When the map loads, it shows position at 0,0. If I drag the map slightly, the marker slowly moves to my correct position. If I (in the samples) reload the same sample or another one, the marker remains stuck at 0,0, even when I drag the map. In summary, I can "fix" the 0,0 marker by interacting with the map but only once.
My device does have gps location enabled, and other location using apps work fine. This including other home made Xamarin forms apps, so this is an issue for MapsUI only.
It failing for both samples and own code makes this a bit confusing.
Does this ring a bell for anyone? Seems a bit strange to say the least.
Note that this also fails on the xamagin/android device emulator with a set position. Just mentioning this as a "fun" extra detail, map longpress event will never fire on my device, but does work on the emulator. I saw someone else, a long time back, complaining about that same issue, and a developer commenting on it being fixed in 2.0, while I see it in 2.3. All in all MapsUI seems like an extremely rich system that I would love to use, but which has weird little bugs and poor support.
The xaml for adding the mapview
<StackLayout>
<mapsui:MapView x:Name="mapView" IsMyLocationButtonVisible="True" />
</StackLayout>
And the c# setup
void start()
{
var status = await Permissions.RequestAsync<Permissions.LocationAlways>();
if(status==PermissionStatus.Denied) return;
var map = new Mapsui.Map
{
Transformation = new MinimalTransformation(),CRS = "EPSG:3857"};
var tileSource = new HttpTileSource(new GlobalSphericalMercator(),
"https://tile.thunderforest.com/landscape/{z}/{x}/{y}.png?
apikey=xxxxxxxxx",new[] { "a", "b", "c" }, name: "OpenStreetMap");
var tileLayer = new TileLayer(tileSource) { Name = "Carto Light" };
map.Layers.Add(tileLayer);
mapView.Map = map;
}
Although not knowing why MyLocationButton not works, but there is a workaround to make the current location to show in MapsUI.
There is a UpdateMyLocation method inside MyLocationLayer,then we can use this method to show the current location programmatically.
In addition, you could use Geolocation to get the current location.
Code as follows:
protected override async void OnAppearing()
{
base.OnAppearing();
var location = await Geolocation.GetLastKnownLocationAsync();
if (location != null)
{
Console.WriteLine($"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}");
}
mapView.MyLocationLayer.UpdateMyLocation(new Position(location.Latitude, location.Longitude), true);
}
The effect:

OpenCV 3 Tracker won't work after reinitialization

I have issue using OpenCV 3 tracking module for tracking. It behaves same, either I use interface class (cv::Tracker) or class with implementation (like cv::TrackerMedianFlow or cv::TrackerMIL, etc). Sample is a bit modified sample from OpenCV sample folder
After correct creation
Ptr<Tracker> tracker = Tracker::create( tracker_algorithm );
if ( tracker == NULL )
{
std::cout << "***Error in the instantiation of the tracker...***\n";
return -1;
}
initialization works just fine
if ( !tracker->init( frame, boundingBox ) )
{
std::cout << "***Could not initialize tracker...***\n";
return -1;
}
Problem occurs late on, withing main loop, when tracking is lost. I use separate detector for defining new target. When I find new target, I clear tracker and initialize it with new value
tracker->clear( );
if ( !tracker->init( frame, detectedNewBBox) )
{
std::cout << "***Could not initialize tracker without history...***\n";
return -1;
}
However, initialization always returns false. I am trying to find out WHY tracker cannot be initialized?
Data was check few time, and looks pretty correct. I even conducted small experiment, trying to initialize tracker right after creation with same data it won't initialize withing loop and it works perfect.
Am I doing something wrong? I was unable to find any documentation on this...
Here is link to available documentation on this:
OpenCV 3 Tracker documentation
Thanks for any effort!
I just ran into the same problem, here's how I got it to work :
tracker->clear();
Ptr<Tracker> trackerNew = Tracker::create( tracker_algorithm );
tracker = trackerNew;
tracker->init( image, boundingBox );
Might not be the right way or the prettiest but it does the job :)
If you want to track a new ROI (region of interest) then I suggest that you should create a new tracker instead of clearing and trying to reuse a previous tracker. Re-use when you need to call init will provide no extra benefit. As you have observed, re-initializing a tracker is not allowed by default.
But if you want to resume tracking of the same object with your correction, it might be possible by doing following steps (I have not tried it myself yet. following code is just a pseudo code)
Ptr<TrackerModel> model = tracker->getModel();
Ptr<TrackerTargetState> lastTargetstate = getLastTargetState();
// Make changes to lastTargetState (update position etc)
// Set lastTargetState, I am not sure if you need to actually set it
// or just editing the object through pointer should work.
model->setLastTargetState(lastTargetstate);
I ran into the same problem and here's my solution:
Open the file in opencv_contrib/modules/tracking/src/tracker.cpp and apply the following changes:
- if( isInit )
+ /*if( isInit )
{
return false;
}
+ */
I recompiled opencv3 and reinstalled it. That fixed it for me. I think they did not want people to reinitialize the tracker for some reason. I am not sure why?

How to find video resolution and aspect ratio of QMediaPlayer video?

This seems too simple, I must be overlooking something?
How do I find the native video size or aspect ratio from a video file being displayed by a QMediaPlayer?
The video Resolution, PixelAspectRatio, etc., should be in the MetaData, but I wait for MetaData Update Signals, and wait for seconds after the video .play()s, but isMetaDataAvailable() always returns false, and .availableMetaData() and .metaData(QMediaMetaData::Resolution).toSize() always return empty.
There seems to be nowhere else to get the video resolution information, or am I missing something?
I can open the video, play the video at full screen, etc.
You can use QVideoWidget instance as video output for QMediaPlayer and retrieve native size of video from QVideoWidget::sizeHint.
QSize MyVideoPlayer::getVideoNativeSize(const QString& videoFilePath)
{
m_mediaPlayer = new QMediaPlayer(0, QMediaPlayer::VideoSurface);
m_mediaPlayer->setVideoOutput(m_videoWidget);
m_mediaPlayer->setMedia(QUrl::fromLocalFile(videoFilePath));
connect(m_mediaPlayer, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
this, SLOT(OnMediaStatusChanged(QMediaPlayer::MediaStatus)));
m_isStoppingVideo = false;
QEventLoop loop;
m_mediaPlayer->play();
while (!m_isStoppingVideo)
{
loop.processEvents();
}
disconnect(m_mediaPlayer, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
this, SLOT(OnMediaStatusChanged(QMediaPlayer::MediaStatus)));
m_mediaPlayer->stop();
return m_videoWidget->sizeHint();
}
void MyVideoPlayer::OnMediaStatusChanged(QMediaPlayer::MediaStatus mediaStatus)
{
if (mediaStatus == QMediaPlayer::BufferedMedia)
{
m_isStoppingVideo = true;
}
}
For finding the resolution without metadata, you can take a look at this question from the Qt Forums for a possible solution:
http://forum.qt.io/topic/31278/solved-get-resolution-of-a-video-file-40-qmediaplayer-41/2
I solved my problem by waiting until the user plays the video and as
soon as they do so i get the QGraphicsVideoItems class property:
nativeSize.
I also solved this problem with QGraphicsVideoItems nativeSize property. But the tricky thing is that nativeSize becomes valid only after some time since you start playing video. The trick is to connect to special QGraphicsVideoItem::nativeSizeChanged(const QSizeF &size) signal that is emitted in case of real nativeSize obtainment.

Change Android default notification sound based on time

I was wondering if it is possible to programmatically change the default notification sound on an Android phone based on what time it is. For instance, I would like the default notification sound to change to Silent after 11PM and then back to a sound at 8AM. I have a working knowledge of Java, but have never done any Android development. Thanks in advance for any help.
Without going too much into detail, I would approach this problem by first creating an AlarmService which will run periodically and change default Ringtone according to your desired time of the day via RingtoneManager
AlarmManager setting up periodical invocations of "RingToneChanger.class" , something like this:
AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, Alarm.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60 * 10, pi); // Millisec * Second * Minute
Then within triggered RingToneChanger.class, ringtone can be changed like this:
if(isNoon) {
RingtoneManager.setActualDefaultRingtoneUri(Context context, RingtoneManager. TYPE_NOTIFICATION , Uri lunchtimeNotificationSound);
} else {
RingtoneManager.setActualDefaultRingtoneUri(Context context, RingtoneManager. TYPE_NOTIFICATION , Uri defaultNotificationsound);
}
Hope it helps. else please don't hesitate to ask.

Resources