Running OpenCV on Raspberry PI - linux

I am trying to test a simple example program on Raspberry PI, to start test OpenCV function on Raspberry PI.
After successful compilation, I get an empty window.
The code is an example code when could be found on the OpenCV website, however the only part I change is name of the picture.
IplImage* img = cvLoadImage("pic1.jpg", 3);
All I get in an empty window. The pic.jpg is saved in the home directory(home/pi).
Anyone came across this before?
Regards

Make sure object file and jpg that you're trying to load is in the same directory. (home)
Or just use complete path like this.
IplImage* img = cvLoadImage("/home/pi/pic1.jpg", 3);
Hope it helps.

Related

QT paly audio by QAudioDevidce can't connect to PulseAudioService

Like title, i'm trying to use Qt and FFmpeg to play audio. My code like this:
QAudioOutput *audio_output;
QIODevice *stream_out;
QAudioFormat audio_fmt;
audio_fmt.setSampleRate(44100);
audio_fmt.setChannelCount(2);
audio_fmt.setSampleSize(16);
audio_fmt.setCodec("audio/pcm");
audio_fmt.setByteOrder(QAudioFormat::LittleEndian);
audio_fmt.setSampleType(QAudioFormat::SignedInt);
QAudioDeviceInfo info = QAudioDeviceInfo::defaultOutputDevice();
if(!info.isFormatSupported(audio_fmt))
{
audio_fmt = info.nearestFormat(audio_fmt);
}
audio_output = new QAudioOutput(audio_fmt);
When i use QAudioDeviceInfo info = QAudioDeviceInfo::defaultOutputDevice()
i get PulseAudioService: pa_context_connect() failed error.
So how can i fix it?
By the way, i'm using Ubuntu 16.04 and Qt 5.14.2, and i have add 'mutilmedia' to Qt pro file
I checked my Qt file ,and i have audio dir in plugins, it's not lib problem. Also, i read this post ,but i don't know how to fix it, anybody have idea? Thank you guys,and my English is bad, wish you can understand what do i say.

Convert images to Icons is giving errors

I'm converting images to icons using this code:
import PIL.image
img = PIL.Image.open ("imagepath.png")
img.save ("iconpath.ico")
This is giving me an icon file as desired, but when I try to open it an error pops up:
Paint:
Microsoft photos error:
When I try to open other icons with the same programs they work perfectly, but it doesn't with the ones I made. Does anyone know any other way or library for doing this?
Try this:
img.save('iconpath.ico',format = 'ICO', sizes=[(32,32)])
You can change size to 16,16
First time I was converting image with PIL I've used this tutorial:
Tutorial
Everything worked fine.
The image that is being converted has to have a 1:1 proportion, if not, when trying to open the generated icon it will cause errors.

Change background of windows 10 using python

I was wondering that can we change windows 10 background using python i did a bit research and find a module name ctypes but the problem was that it needs a image to apply but i want that instead of a locally saved file it should use a url of a image and refresh the background at a interval with a new image. Cuz i want to create a script which will apply an anime wallpaper in every 5 minute and the url will be taken from a api.
Please Help!
On Windows with python2.5 or higher, use ctypes to load user32.dll and call SystemParametersInfo() with SPI_SETDESKWALLPAPER action.
For example:
import ctypes
SPI_SETDESKWALLPAPER = 20
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, "image.jpg" , 0)
Your script will have to do that in two steps
Download the image from the url using a package like requests
Set the Windows Background

Tkinter and some kind of issue when trying to display images

First off, I'm very new to Python and coding in general. I'm using Python, Tkinter, and Idle version 3.7.3. I'm using an HP Chromebook, with Chrome OS Version 81.0.4044.141.
from tkinter import *
window = Tk()
window.title('Image Example')
img = PhotoImage(file = 'python.gif')
label = Label(window, image = img)
label.pack()
window.mainloop()
As you can see above, this is the small snippet of code that I'm having issues with. As far as I understand, everything is written correctly and the file "python.gif" is in the correct directory. For reference this is what the image should look like:
python.gif (normal)
But when I run the program, this is what I get:
python.gif (screenshot of running program)
That's the result 99% of the time, but I should mention that there have been a RARE number of occasions where the image displayed correctly upon program execution. However, I do not know how to replicate that. Also for more context, I've tried other images to see what happened. I found a free .pgm image to try as an example, and upon execution either I got the same result, or half of the image would appear correctly while the bottom half (also sometimes this would be reversed and the top half would be affected) would be "blacked out".
In conclusion, I wanted to ask if anybody has an idea of what's going on. I'm not sure if this is a hardware issue (because I can view all mentioned images in a normal image viewing app with no problems), or if this has something to do with Python/Tkinter.
Any assistance is very appreciated! Please and Thank You!

How to stream depth image from a basic ToF camera module with Point Cloud Library(PCL)

Inforamtion:
I have a simple ToF(Time of Flight) camera module provided by a vendor that only contains a Depth Node.
I've already setup the PCL environment and can compile and execute the sample code it provides.
The ToF camera module comes with a source code shows how to get depth raw data(the x, y, z value) from the hard device, but doesn't tell how to stream it as both point cloud image and depth image.
Win 7 64bit, Visual Studio 2008, PCL all-in-one 32bit.
As a result, I plan to use PCL to show the Point cloud image and depth image with the x, y, z data I can get from that camera module, further more, if streaming is possible.
However, as far as I know right now is that PCL tends to store all the point cloud data as a .pcd file, and then reads it thus output a point cloud image and a depth image.
It is obviously too slow to do the streaming in such way if I have to savePCD() and readPCD() every time in each frame. So I studied the "openni grabber" and "openni range image visualization" sample code and tried execute them, sadly "No device connected." is all I got.
I have a few ideas to ask for advises before I try:
Is there a way to use Openni on a device except Kinect, Xtion and PrimeSense? Even if it's just a device with no name and only has a depth node?
Can PCL show point cloud image and depth image without accessing a .pcd file? In other words, can I just assign the value of each vertex and construct a image?
Can I just normalize all the vertices and construct a image with barely Opencv?
Is there any other method to stream that ToF camera module in point cloud image and depth image?
1) Changing the OpenNI grabber to use your own ToF camera will be much more work than to just use the example from the camera in a loop shown below.
2) Yes PCL can show point cloud image and depth without accessing a .pcd file. What the .pcd loader does is to parse the pcd-file and place the values in the cloud format. You can do this directly from your camera data as shown below.
3) No idea what you mean here. I propose you try to use the pcl visualizer or cloud viewer as proposed below.
You can do something like:
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
cloud->isDense = true;
cloud->width = widthOfTOFsensor;
cloud->height = heightOfTOFsensor;
cloud->size = cloud->width * cloud->height;
//Create some loop
//grabNewFrame from TOFsensor
for(int pointIndex=0;pointIndex<cloud->size();pointIndex++)
{
cloud->points[pointIndex].x = tofSensorData[pointIndex].x; //Don't know the tofData format, so I just guessed something.
cloud->points[pointIndex].y = tofSensorData[pointIndex].y;
cloud->points[pointIndex].z = tofSensorData[pointIndex].z;
}
// Plot the data using pcl visualizer or cloud viewer, see:
http://pointclouds.org/documentation/tutorials/cloud_viewer.php#cloud-viewer
http://pointclouds.org/documentation/tutorials/pcl_visualizer.php#pcl-visualizer

Resources