I want to change VideoStream setting in my program, but it doesn't work
#include <OpenNI.h>
int main()
{
OpenNI::initialize();
Device device;
device.open(ANY_DEVICE);
VideoStream depthStream;
depthStream.create(device, SENSOR_DEPTH);
depthStream.start();
VideoMode depthMode;
depthMode.setFps(20);
depthMode.setResolution(640, 480);
depthMode.setPixelFormat(PIXEL_FORMAT_DEPTH_100_UM);
depthStream.setVideoMode(depthMode);
...
}
Even I change depthStream.start() line after setVideoMode() function, but still doesn't work.
I changed Fps to 24, 20, 5, 1 but it doesn't change anything.
p.s. : This is my simple code, without error handling.
Edit:
Answer:
with the help of dear "api55" i found that my device (Kinect Xbox) support only one mode of videoMode. so I can't change it.
My only supported video is :
FPS:30
Width:640
Height:480
I change the VideoMode succesfully in a code a did before. After creating the VideoStream you should do something like:
rc = depth.create(device, openni::SENSOR_DEPTH);
if (rc != openni::STATUS_OK)
error_manager(3);
// set the new resolution and fps
openni::VideoMode depth_videoMode = depth.getVideoMode();
depth_videoMode.setResolution(frame_width,frame_height);
depth_videoMode.setFps(30);
depth.setVideoMode(depth_videoMode);
rc = depth.start();
if (rc != openni::STATUS_OK)
error_manager(4);
First I get the VideoMode that is inside the stream to conserve the other values and only change what I wanted. I think your code should work, but not all settings work in all cameras. To check the possible settings you can use the function openni::VideoStream::getSensorInfo. The code to check this should be something like:
#include <OpenNI.h>
int main()
{
OpenNI::initialize();
Device device;
device.open(ANY_DEVICE);
VideoStream depthStream;
depthStream.create(device, SENSOR_DEPTH);
depthStream.start();
SensorInfo& info = depthStream.getSensorInfo();
Array& videoModes = info.getSupportedVideoModes();
for (int i = 0; i < videoModes.getSize(); i++){
std::cout << "VideoMode " << i << std::endl;
std::cout << "FPS:" << videoModes[i].getFps() << std::endl;
std::cout << "Width:" << videoModes[i].getResolutionX() << std::endl;
std::cout << "Height:" << videoModes[i].getResolutionY() << std::endl;
}
...
}
I haven't test this last piece of code, so it may have errors, but you get the idea of it. The supported settings change with each camera, but I think the supported FPS in my camera were 15 and 30.
I hope this helps you
Related
I am creating a background music player and I wanted to use the MPV C Plugin to do so, but my problem arrives when I disable displaying the video (with check_error(mpv_set_option_string(ctx, "vid", "no"));, this does the job of disabling the video, but then I can't use keys (like q (quit) or > (skip)) anymore... How do I allow them to be used in the terminal without the video GUI?
My Code:
#include <iostream>
#include <mpv/client.h>
static inline void check_error(int status)
{
if (status < 0)
{
std::cout << "mpv API error: " << mpv_error_string(status) << std::endl;
exit(1);
}
}
int main(int argc, char *argv[])
{
if (argc != 2)
{
std::cout << "pass a single media file as argument" << std::endl;
return 1;
}
mpv_handle *ctx = mpv_create();
if (!ctx)
{
std::cout << "failed creating context" << std::endl;
return 1;
}
check_error(mpv_set_option_string(ctx, "input-default-bindings", "yes"));
mpv_set_option_string(ctx, "input-vo-keyboard", "yes");
int val = 1;
check_error(mpv_set_option(ctx, "osc", MPV_FORMAT_FLAG, &val));
check_error(mpv_initialize(ctx));
const char *cmd[] = {"loadfile", argv[1], NULL};
check_error(mpv_command(ctx, cmd));
// THIS IS WHAT I USE TO DISABLE THE VIDEO
// check_error(mpv_set_option_string(ctx, "vid", "no"));
// Let it play, and wait until the user quits.
while (1)
{
mpv_event *event = mpv_wait_event(ctx, 10000);
std::cout << "event: " << mpv_event_name(event->event_id) << std::endl;
if (event->event_id == MPV_EVENT_SHUTDOWN)
break;
}
mpv_terminate_destroy(ctx);
return 0;
}
As you can see with mpv_set_option_string(ctx, "input-default-bindings", "yes") I allow it to use keybinding, but how do I make the keybinding works with just the terminal, since it only works when the GUI is visible? If you ran: mpv path/to/video.mp3 --no-video then the key bindings would still work fine, even without the video GUI.
i was porting my game to emscripten. Everything was fine until SDL_ttf.
Actually i am using sdl2 + sdl2 image + sdl mixer.
I will show an example:
SDL_Color color = {255,255,255};
std::cout << "1\n";
font = TTF_OpenFont("saucery/font/font1.otf", 8);
if (!font)
printf("Unable to load font: %s \n", TTF_GetError());
std::cout << "2\n";
SDL_Surface *surf = TTF_RenderText_Solid(font,"Oieee",color);
std::cout << "3\n";
if (surf){
std::cout << (int)surf << "\n";
texture = SDL_CreateTextureFromSurface(Game::instance->GetRenderer(),surf);
std::cout << "4\n";
Uint32 format;
int acess,w,h;
SDL_QueryTexture(texture, &format,&acess,&w,&h);
dimensions2.x = 0;
dimensions2.y = 0;
dimensions2.h = h;
dimensions2.w = w;
SDL_FreeSurface(surf);
}
In this code i just open an font (i have already changed the size and the type to .ttf). Everything seems to run fine until:
SDL_CreateTextureFromSurface
I put some std::cout to see where the code was "crashing". Everytime it calls the createTextureFrom on the console shows to me "45" and the running stops there.
Even with any std::cout i still get this error.
this is driving me crazy already ._.
I am trying to integrate a code already written in ROS with some basic Visp lines so as to display a camera feed using Visp functions. I am a beginner in visp and hence I am trying something basic.I am attaching the relevant code lines here
//Lots of lines of code above and blow this code block
cv::Mat src_gray;
cv::cvtColor(imageLeft, src_gray, CV_RGB2GRAY );//imageLeft is a colour image got from the camera through another node
vpImage<unsigned char> I;
vpImageConvert::convert(src_gray,I) ;
vpDisplayOpenCV display;
if(this->lt == false)//this if loop is to prevent from infinite windows coming out
{display.init(I, 100, 100, "Line tracking");
this->lt = true;}
vpDisplay::display(I);
vpDisplay::flush(I);
Let me ensure you that this piece of code is in a callback and hence it is equivalent to an infinte while loop unless the process is stopped.
I am not able to get the camera output in the window.When I run the node the window opens but no image.Any ideas?
The ViSP-ROS interfece has been changing recently. While ViSP Bridge provides low level interface between ROS and ViSP, Visp ROS is a better and higher level interface. From there you can reach to this tutorial where a regular ViSP code is modified to use ROS.
The ViSP code similar to yours:
#include <visp/vp1394TwoGrabber.h>
#include <visp/vpDisplayX.h>
#include <visp/vpImage.h>
int main()
{
#ifdef VISP_HAVE_DC1394_2
try {
vpImage<unsigned char> I; // Create a gray level image container
bool reset = true; // Enable bus reset during construction (default)
vp1394TwoGrabber g(reset); // Create a grabber based on libdc1394-2.x third party lib
g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_640x480_MONO8);
g.setFramerate(vp1394TwoGrabber::vpFRAMERATE_60);
g.open(I);
std::cout << "Image size: " << I.getWidth() << " " << I.getHeight() << std::endl;
#ifdef VISP_HAVE_X11
vpDisplayX d(I);
#else
std::cout << "No image viewer is available..." << std::endl;
#endif
while(1) {
g.acquire(I);
vpDisplay::display(I);
vpDisplay::flush(I);
if (vpDisplay::getClick(I, false))
break;
}
}
catch(vpException e) {
std::cout << "Catch an exception: " << e << std::endl;
}
#endif
}
And the ROS enabled code:
#include <visp/vpDisplayX.h>
#include <visp/vpImage.h>
#include <visp_ros/vpROSGrabber.h>
int main()
{
try {
//vpImage<unsigned char> I; // Create a gray level image container
vpImage<vpRGBa> I; // Create a color image container
vpROSGrabber g; // Create a grabber based on ROS
g.setCameraInfoTopic("/camera/camera_info");
g.setImageTopic("/camera/image_raw");
g.setRectify(true);
g.open(I);
std::cout << "Image size: " << I.getWidth() << " " << I.getHeight() << std::endl;
#ifdef VISP_HAVE_X11
vpDisplayX d(I);
#else
std::cout << "No image viewer is available..." << std::endl;
#endif
while(1) {
g.acquire(I);
vpDisplay::display(I);
vpDisplay::flush(I);
if (vpDisplay::getClick(I, false))
break;
}
}
catch(vpException e) {
std::cout << "Catch an exception: " << e << std::endl;
}
}
Hope this helps!
I'm in the process of porting my engine across to Linux support.
I can successfully create a window, and set up an OpenGL context however, the contents of the window are whatever was displayed behind it at the time of creation. NOTE: This is not a transparent window, if I drag the window around it still contains an 'image' of whatever was behind it at the time of creation. (See attached image).
Now I'm not sure where the issue could be, however I'm not looking for a solution to a specific issue in my code, mainly just any insight from other Linux/GLX developers who may have seen a similar issue and might know where I should start looking?
I stripped all the code in my update function right down to just be:
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glXSwapBuffers(dpy, win);
With no joy. My first thought was that it was garbage, but with just those calls I'd expect to the see the glClearColor().
glGetError() returns no errors anywhere in my application.
Immediately after glXCreateContext() I then call glXMakeCurrent() and calling glGetIntegerv() with GL_MAJOR_VERSION and GL_MINOR_VERSION returns 4 and 2 (4.2) respectively which indicates the GL context has been created successfully.
I tried having a glXMakeCurrent() call immediately before I try my glClear/glXSwapBuffers() but to effect.
Further info!, this is a multithreaded application, however all X11/GLX/OpenGL calls are only made by a single thread. I have also tried calling XInitThreads() from the main application thread, and from the Rendering thread with no luck either.
Code for Creating Window
bool RenderWindow::createWindow(std::string title, unsigned int width, unsigned int height)
{
std::cout << "createWindow() called" << std::endl;
this->m_Width = width;
this->m_Height = height;
this->m_Display = XOpenDisplay(NULL);
if (this->m_Display == NULL)
{
std::cout << "Unable to connect to X Server" << std::endl;
return false;
}
this->m_Root = DefaultRootWindow(this->m_Display);
this->m_Active = true;
XSetErrorHandler(RenderWindow::errorHandler);
return true;
}
Code for initialising OpenGL Context
bool RenderingSubsystem::initialiseContext()
{
if(!this->m_Window)
{
std::cout << "Unable to initialise context because there is no Window" << std::endl;
return false;
}
this->m_Window->createWindow(this->m_Window->GetTitle(), this->m_Window->GetWidth(), this->m_Window->GetHeight());
int att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None };
this->m_VI = glXChooseVisual(this->m_Window->GetDisplay(), 0, att);
if (this->m_VI == NULL)
{
std::cout << "Unable to initialise context because no suitable VisualInfo could be found" << std::endl;
return false;
}
this->m_CMap = XCreateColormap(this->m_Window->GetDisplay(), this->m_Window->GetHandle(), this->m_VI->visual, AllocNone);
this->m_SWA.colormap = this->m_CMap;
this->m_SWA.event_mask = ExposureMask;
std::cout << "Width: " << this->m_Window->GetWidth() << " Height: " << this->m_Window->GetHeight() << std::endl;
this->m_Wnd = XCreateWindow(this->m_Window->GetDisplay(), this->m_Window->GetHandle(), 0, 0, this->m_Window->GetWidth(), this->m_Window->GetHeight(), 0, this->m_VI->depth, InputOutput, this->m_VI->visual, CWColormap | CWEventMask, &this->m_SWA);
XMapWindow(this->m_Window->GetDisplay(), this->m_Wnd);
XStoreName(this->m_Window->GetDisplay(), this->m_Wnd, this->m_Window->GetTitle().c_str());
this->m_DC = glXCreateContext(this->m_Window->GetDisplay(), this->m_VI, NULL, GL_TRUE);
if(this->m_DC == 0)
{
std::cout << "Unable to create GL Context" << std::endl;
return false;
}
glXMakeCurrent(this->m_Window->GetDisplay(), this->m_Window->GetHandle(), this->m_DC);
int major, minor;
glGetIntegerv( GL_MAJOR_VERSION, &major );
glGetIntegerv( GL_MINOR_VERSION, &minor );
std::cout << "InitialiseContext complete (" << major << "." << minor << ")" << std::endl;
return true;
}
I read and tried all the other posts to that topic, but nothing helped. When I try to play music with Mix_PlayChannel() I don't get an error nor do I hear some sound! I tried for hours now and nothing helps. The program just finishes happily. But no sound! I am using Ubuntu 12.04 64bit.
Thanks!
[EDIT]
Here is the code I use:
#include <iostream>
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
int main(int argc, char** argv) {
Mix_Music *music = NULL;
Mix_Chunk *wave = NULL;
SDL_Init(SDL_INIT_AUDIO);
int audio_rate = 44100;
Uint16 audio_format = AUDIO_S16; /* 16-bit stereo */
int audio_channels = 1;
int audio_buffers = 4096;
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) < 0) {
printf("Unable to open audio!\n");
exit(1);
}
if(Mix_Init(MIX_INIT_MOD) != MIX_INIT_MOD)
std::cout << "errer";
Mix_Volume(-1, MIX_MAX_VOLUME);
music = Mix_LoadMUS("1.wav");
wave = Mix_LoadWAV("1.wav");
if (music == NULL) {
std::cout << "Could not load 1.wav\n";
std::cout << Mix_GetError();
}
if (wave == NULL) {
std::cout << "Could not load 1.wav\n";
std::cout << Mix_GetError();
}
Mix_VolumeChunk(wave, MIX_MAX_VOLUME);
Mix_VolumeMusic(MIX_MAX_VOLUME);
Mix_PlayMusic(music, 0);
std::cout << Mix_GetError();
Mix_FadeInChannelTimed(-1, wave, 0, 100,1);
std::cout << Mix_GetError();
return 1;
}
I try both PlayMusic() and Mix_FadeInChannelTimed(). Both files are loaded correctly but not played. Sound is not muted, wav-file is playable with aplay or other tools. I check with alsamixer that all channels are open and not too low.
I now found out that the program needs to run until the sound has finished playing! I added a usleep() command after the play command and it plays nicely. So that was really mentioned nowhere that PlayMusic() does not keep running.