I want to build only a graphical buffer, and not send my graphics to screen.
I will catch the buffer with openCV periodically and send the pics over UDP to another computer (using gstreamer), where the graphics will be shown.
How can I make a buffer without it being shown on screen (of the local computer) . I read the API and making a OsMesaGraphicsPipe would be the trick (it only resides in buffer ??) but could not make it work.
Below the code to create the openCV buffer (just one, not periodically called), I can only create it after the mainloop is called (or a few PandaFramework.do_frame calls).
I suspect that I only have to change the line: WindowFramework *window = framework.open_window();
and call it with a pipe , but dont know how to do this succesfully.
//g++ one.cxx -o one -I/usr/include/panda3d -L/usr/lib/panda3d -I/usr/include/python2.7 -lp3framework -lpanda -lpandafx -lpandaexpress -lp3dtoolconfig -lp3dtool -lp3pystub -lp3direct -lopencv_core -lopencv_highgui
#include "pandaFramework.h"
#include "pandaSystem.h"
#include "genericAsyncTask.h"
#include "asyncTaskManager.h"
#include "cIntervalManager.h"
#include "cLerpNodePathInterval.h"
#include "cMetaInterval.h"
#include "auto_bind.h"
#include "directionalLight.h"
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <iostream>
using namespace cv;
// Global stuff
PandaFramework framework;
PT(AsyncTaskManager) taskMgr = AsyncTaskManager::get_global_ptr();
PT(ClockObject) globalClock = ClockObject::get_global_clock();
NodePath camera;
AsyncTask::DoneStatus example_task(GenericAsyncTask* task, void* data){
WindowFramework *window = (WindowFramework *) data;
PT(DisplayRegion) displayRegion = window->get_display_region_3d();
int width = displayRegion->get_pixel_width();
int height = displayRegion->get_pixel_height();
PT(Texture) tex = displayRegion->get_screenshot();
CPTA_uchar ding = tex->get_ram_image_as("BGR");
string buffer = ding.get_data();
void * c = (void *) &buffer[0];
// void * ptr = (void *) (&ding);
//void * ptr3 = (void *) ding;
Mat cv_frame = Mat(cv::Size(width, height), CV_8UC3, c);
cv::flip(cv_frame,cv_frame,0);
imshow("CV window", cv_frame);
waitKey(2000);
return AsyncTask::DS_done;
}
int main(int argc, char *argv[]) {
// Open a new window framework and set the title
framework.open_framework(argc, argv);
framework.set_window_title("My Panda3D Window");
// Open the window
//OsMesaGraphicsPipe *pipe = new OsMesaGraphicsPipe();
WindowFramework *window = framework.open_window();
camera = window->get_camera_group();
// Load the environment model
NodePath Actor = window->load_model(framework.get_models(), "panda.egg");
// Load the walk animation
window->load_model(Actor, "panda-walk.egg");
AnimControlCollection anim_collection;
auto_bind(Actor.node(), anim_collection);
anim_collection.pose("panda-walk", 0);
Actor.reparent_to(window->get_render());
camera.set_pos(0, -30, 6);
PT(DirectionalLight) d_light;
d_light = new DirectionalLight("my d_light");
NodePath dlnp = window->get_render().attach_new_node(d_light);
PT(GenericAsyncTask) task;
//Add the task_func function with an upon_death callback
task = new GenericAsyncTask("CV bufferke", &example_task, (void*) window);
task->set_delay(1); // zodat eerst mainloop wordt gedraaid !!
taskMgr->add(task);
// Run the engine.
// hereunder is same as framework.main_loop();
// But now you can let other mainloop (gstreamer) run panda loop
while(1) {
framework.do_frame(Thread::get_current_thread());
}
framework.close_framework();
return (0);
}