filmout_display now loads a blank image on startup and displays it. Logic for loading and displaying arbitrary images still needed.
This commit is contained in:
parent
4a68abd38e
commit
78cca62c12
|
@ -34,8 +34,8 @@ class State {
|
||||||
vector<uint64_t> exposure = {};
|
vector<uint64_t> exposure = {};
|
||||||
uint64_t x;
|
uint64_t x;
|
||||||
uint64_t y;
|
uint64_t y;
|
||||||
uint64_t width;
|
uint64_t w;
|
||||||
uint64_t height;
|
uint64_t h;
|
||||||
bool active = false;
|
bool active = false;
|
||||||
bool ERROR = false;
|
bool ERROR = false;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ class State {
|
||||||
Mode getMode() { return mode; }
|
Mode getMode() { return mode; }
|
||||||
string getImage () { return image; }
|
string getImage () { return image; }
|
||||||
vector<uint64_t> getExposure() { return exposure; }
|
vector<uint64_t> getExposure() { return exposure; }
|
||||||
vector<uint64_t> getPosition() { return { x, y, width, height }; }
|
vector<uint64_t> getPosition() { return { x, y, w, h }; }
|
||||||
bool isError () { return ERROR; }
|
bool isError () { return ERROR; }
|
||||||
void setActive () { active = true; }
|
void setActive () { active = true; }
|
||||||
bool isActive () { return active; }
|
bool isActive () { return active; }
|
||||||
|
|
168
src/main.cpp
168
src/main.cpp
|
@ -2,7 +2,7 @@
|
||||||
#include "state.hpp"
|
#include "state.hpp"
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include <OpenGL/gl.h>
|
#include <OpenGL/gl.h>
|
||||||
#include <OpenGL/gl3.h>
|
#include <OpenGL/gl3.h>
|
||||||
#include <GLUT/glut.h>
|
#include <GLUT/glut.h>
|
||||||
#else
|
#else
|
||||||
|
@ -25,8 +25,8 @@ using namespace std;
|
||||||
const uint16_t PORT = 8081;
|
const uint16_t PORT = 8081;
|
||||||
const uint16_t BUFFER_SIZE = 2048;
|
const uint16_t BUFFER_SIZE = 2048;
|
||||||
|
|
||||||
GLuint imageTexture;
|
GLuint imageTexture = 0;
|
||||||
GLuint blankTexture;
|
GLuint blankTexture = 0;
|
||||||
|
|
||||||
GLint screenWidth = 0;
|
GLint screenWidth = 0;
|
||||||
GLint screenHeight = 0;
|
GLint screenHeight = 0;
|
||||||
|
@ -34,26 +34,24 @@ GLint screenHeight = 0;
|
||||||
Image img;
|
Image img;
|
||||||
State state;
|
State state;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void actionDisplay () {
|
void actionDisplay () {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void actionLoad () {
|
void actionLoad () {
|
||||||
string imagePath = state.getImage();
|
string imagePath = state.getImage();
|
||||||
vector<uint64_t> position = state.getPosition();
|
vector<uint64_t> position = state.getPosition();
|
||||||
Mat image = img.loadImage(imagePath, position[0], position[1], position[2], position[3]);
|
Mat image = img.loadImage(imagePath, position[0], position[1], position[2], position[3]);
|
||||||
glGenTextures(2, &imageTexture);
|
glGenTextures(2, &imageTexture);
|
||||||
glBindTexture(GL_TEXTURE_2D, imageTexture);
|
glBindTexture(GL_TEXTURE_2D, imageTexture);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||||
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, // Type of texture
|
glTexImage2D(GL_TEXTURE_2D, // Type of texture
|
||||||
0, // Pyramid level (for mip-mapping) - 0 is the top level
|
0, // Pyramid level (for mip-mapping) - 0 is the top level
|
||||||
GL_RGB, // Internal colour format to convert to
|
GL_RGB, // Internal colour format to convert to
|
||||||
image.cols, // Image width i.e. 640 for Kinect in standard mode
|
image.cols, // Image width i.e. 640 for Kinect in standard mode
|
||||||
|
@ -69,17 +67,17 @@ void actionStop () {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadBlank () {
|
void loadBlank () {
|
||||||
Mat blank = img.getBlank();
|
Mat blank = img.getBlank();
|
||||||
|
|
||||||
glGenTextures(1, &blankTexture);
|
glGenTextures(1, &blankTexture);
|
||||||
glBindTexture(GL_TEXTURE_2D, blankTexture);
|
glBindTexture(GL_TEXTURE_2D, blankTexture);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
glTexImage2D(GL_TEXTURE_2D, // Type of texture
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
|
||||||
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, // Type of texture
|
|
||||||
0, // Pyramid level (for mip-mapping) - 0 is the top level
|
0, // Pyramid level (for mip-mapping) - 0 is the top level
|
||||||
GL_RGB, // Internal colour format to convert to
|
GL_RGB, // Internal colour format to convert to
|
||||||
blank.cols, // Image width i.e. 640 for Kinect in standard mode
|
blank.cols, // Image width i.e. 640 for Kinect in standard mode
|
||||||
|
@ -91,27 +89,32 @@ void loadBlank () {
|
||||||
}
|
}
|
||||||
|
|
||||||
void display () {
|
void display () {
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glViewport(0, 0, screenWidth, screenHeight);
|
glViewport(0, 0, screenWidth, screenHeight);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
|
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
|
||||||
glBindTexture(GL_TEXTURE_2D, imageTexture);
|
glBindTexture(GL_TEXTURE_2D, blankTexture);
|
||||||
|
|
||||||
glBegin(GL_QUADS); // front face
|
glBegin(GL_QUADS); // front face
|
||||||
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 0.0f); //bottom right
|
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 0.0f); //bottom right
|
||||||
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); //top right
|
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); //top right
|
||||||
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); //top left
|
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); //top left
|
||||||
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f); //bottom left
|
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f); //bottom left
|
||||||
glEnd();
|
glEnd();
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
|
|
||||||
//glFlush();
|
//glFlush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void timer(int value) {
|
||||||
|
glutPostRedisplay();
|
||||||
|
glutTimerFunc(1, timer, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* State Message Variables
|
* State Message Variables
|
||||||
**/
|
**/
|
||||||
|
@ -133,26 +136,26 @@ condition_variable sendCondVar;
|
||||||
|
|
||||||
void processMessage () {
|
void processMessage () {
|
||||||
if (receivedMessage) {
|
if (receivedMessage) {
|
||||||
cout << "RECEIVED" << endl;
|
cout << "RECEIVED" << endl;
|
||||||
state.receiveMessage(incomingMessage);
|
state.receiveMessage(incomingMessage);
|
||||||
receivedMessage = false;
|
receivedMessage = false;
|
||||||
|
|
||||||
while (state.isActive()) {
|
while (state.isActive()) {
|
||||||
if (state.getAction() == LOAD) {
|
if (state.getAction() == LOAD) {
|
||||||
actionLoad();
|
actionLoad();
|
||||||
} else if (state.getAction() == DISPLAY) {
|
} else if (state.getAction() == DISPLAY) {
|
||||||
actionDisplay();
|
actionDisplay();
|
||||||
} else if (state.getAction() == STOP) {
|
} else if (state.getAction() == STOP) {
|
||||||
actionStop();
|
actionStop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.isError()) {
|
if (state.isError()) {
|
||||||
outgoingMessage = state.createMessage(false);
|
outgoingMessage = state.createMessage(false);
|
||||||
} else {
|
} else {
|
||||||
outgoingMessage = state.createMessage(true);
|
outgoingMessage = state.createMessage(true);
|
||||||
}
|
}
|
||||||
sendMessage = true;
|
sendMessage = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,28 +185,28 @@ void handleTCPConnection(int clientSocket) {
|
||||||
bool localSendMessage;
|
bool localSendMessage;
|
||||||
string localOutgoingMessage;
|
string localOutgoingMessage;
|
||||||
|
|
||||||
{
|
{
|
||||||
unique_lock<mutex> lock(sendMutex);
|
unique_lock<mutex> lock(sendMutex);
|
||||||
sendCondVar.wait(lock, [&] { return sendMessage; });
|
sendCondVar.wait(lock, [&] { return sendMessage; });
|
||||||
localSendMessage = sendMessage;
|
localSendMessage = sendMessage;
|
||||||
localOutgoingMessage = outgoingMessage;
|
localOutgoingMessage = outgoingMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (localSendMessage) {
|
if (localSendMessage) {
|
||||||
const char* msg = localOutgoingMessage.c_str();
|
const char* msg = localOutgoingMessage.c_str();
|
||||||
int bytesSent = send(clientSocket, msg, strlen(msg), 0);
|
int bytesSent = send(clientSocket, msg, strlen(msg), 0);
|
||||||
if (bytesSent < 0) {
|
if (bytesSent < 0) {
|
||||||
cerr << "Error sending ACK to client" << endl;
|
cerr << "Error sending ACK to client" << endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(buffer, 0, BUFFER_SIZE);
|
memset(buffer, 0, BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void runTCPServer (int serverSocket) {
|
void runTCPServer (int serverSocket) {
|
||||||
while (true) {
|
while (true) {
|
||||||
struct sockaddr_in clientAddr;
|
struct sockaddr_in clientAddr;
|
||||||
socklen_t clientAddrLen = sizeof(clientAddr);
|
socklen_t clientAddrLen = sizeof(clientAddr);
|
||||||
|
|
||||||
|
@ -220,25 +223,26 @@ void runTCPServer (int serverSocket) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t handleArgs (int argc, char** argv) {
|
uint8_t handleArgs (int argc, char** argv) {
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
screenWidth = atoi(argv[1]);
|
screenWidth = atoi(argv[1]);
|
||||||
cout << "Set width: " << screenWidth << endl;
|
cout << "Set width: " << screenWidth << endl;
|
||||||
} else {
|
} else {
|
||||||
cerr << "Please provide screen width as first argument" << endl;
|
cerr << "Please provide screen width as first argument" << endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
screenHeight = atoi(argv[2]);
|
screenHeight = atoi(argv[2]);
|
||||||
cout << "Set height: " << screenHeight << endl;
|
cout << "Set height: " << screenHeight << endl;
|
||||||
} else {
|
} else {
|
||||||
cerr << "Please provide screen height as second argument" << endl;
|
cerr << "Please provide screen height as second argument" << endl;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
cout << screenWidth << "x" << screenHeight << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char** argv) {
|
int main (int argc, char** argv) {
|
||||||
uint8_t argsRet = handleArgs(argc, argv);
|
uint8_t argsRet = handleArgs(argc, argv);
|
||||||
|
|
||||||
if (argsRet > 0) {
|
if (argsRet > 0) {
|
||||||
return argsRet;
|
return argsRet;
|
||||||
|
@ -246,15 +250,14 @@ int main (int argc, char** argv) {
|
||||||
|
|
||||||
img.setDimensions( (uint16_t) screenWidth, (uint16_t) screenHeight);
|
img.setDimensions( (uint16_t) screenWidth, (uint16_t) screenHeight);
|
||||||
|
|
||||||
loadBlank();
|
|
||||||
|
|
||||||
glutInit(&argc, argv);
|
glutInit(&argc, argv);
|
||||||
glutInitDisplayMode(GLUT_SINGLE);
|
glutInitDisplayMode(GLUT_SINGLE);
|
||||||
glutCreateWindow("opengl_opencv_example");
|
glutCreateWindow("opengl_opencv_example");
|
||||||
glutSetCursor(GLUT_CURSOR_NONE);
|
glutSetCursor(GLUT_CURSOR_NONE);
|
||||||
glutFullScreen();
|
glutFullScreen();
|
||||||
glutDisplayFunc(display);
|
glutDisplayFunc(display);
|
||||||
glutMainLoop();
|
glutTimerFunc(0, timer, 0);
|
||||||
|
loadBlank();
|
||||||
|
|
||||||
int serverSocket = socket(AF_INET, SOCK_STREAM, 0);
|
int serverSocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (serverSocket < 0) {
|
if (serverSocket < 0) {
|
||||||
|
@ -282,11 +285,12 @@ int main (int argc, char** argv) {
|
||||||
cout << "TCP server listening on port " << PORT << endl;
|
cout << "TCP server listening on port " << PORT << endl;
|
||||||
|
|
||||||
thread serverThread(runTCPServer, serverSocket);
|
thread serverThread(runTCPServer, serverSocket);
|
||||||
|
|
||||||
|
glutMainLoop();
|
||||||
|
|
||||||
serverThread.join();
|
serverThread.join();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
close(serverSocket);
|
close(serverSocket);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -37,9 +37,9 @@ void State::setMode (json& msgData) {
|
||||||
void State::setPosition (json& msgData) {
|
void State::setPosition (json& msgData) {
|
||||||
x = msgData["position"]["x"];
|
x = msgData["position"]["x"];
|
||||||
y = msgData["position"]["y"];
|
y = msgData["position"]["y"];
|
||||||
width = msgData["position"]["w"];
|
w = msgData["position"]["w"];
|
||||||
height = msgData["position"]["h"];
|
h = msgData["position"]["h"];
|
||||||
cout << "Position[x] = " << x << " [y] = " << y << " [width] = " << width << " [height] = " << height << endl;
|
cout << "Position[x] = " << x << " [y] = " << y << " [w] = " << w << " [h] = " << h << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void State::setExposure (json& msgData) {
|
void State::setExposure (json& msgData) {
|
||||||
|
|
Loading…
Reference in New Issue