forked from wsu-lug/lug-fishtank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebcamPassthrough.hpp
89 lines (78 loc) · 3.02 KB
/
WebcamPassthrough.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include<opencv2/opencv.hpp>
#include "PriDrawable.hpp"
//#include <X11/Xlib.h>
#include <thread>
class WebcamPassthrough : public PriDrawable {
private:
cv::VideoCapture cap;
cv::Mat frameRGB;
int width, height;
int counter;
public:
WebcamPassthrough(int width, int height, SDL_Renderer * renderer) : PriDrawable(0, renderer, width, height) {
cap = cv::VideoCapture(-1);
this->width = width;
this->height = height;
counter = 0;
if(!cap.isOpened()) {
return;
}
//cap.set(CV_CAP_PROP_FRAME_WIDTH,400);
//cap.set(CV_CAP_PROP_FRAME_HEIGHT,300);
cap >> frameRGB;
// auto thing = sf::seconds(1);
// sf::sleep(thing);
//cv::cvtColor(frameRGB,frameRGBA,cv::COLOR_BGR2RGBA);
std::cout << "FUCK" << std::endl;
IplImage opencvimg2 = (IplImage)frameRGB;
IplImage* opencvimg = &opencvimg2;
SDL_Surface * frameSurface = SDL_CreateRGBSurfaceFrom(
(void*)opencvimg->imageData,
opencvimg->width, opencvimg->height,
opencvimg->depth*opencvimg->nChannels,
opencvimg->widthStep,
0xff0000, 0x00ff00, 0x0000ff, 0);
std::cout << "FUCK" << std::endl;
SDL_Texture * vidframe = SDL_CreateTextureFromSurface(renderer, frameSurface);
SDL_FreeSurface(frameSurface);
std::cout << "FUCK2" << std::endl;
textures.push_back(vidframe);
auto newthread = std::thread(&WebcamPassthrough::frameGrabberThread, this, std::ref(cap));
newthread.detach();
}
void frameGrabberThread(cv::VideoCapture &cap2) {
cap2.grab();
}
void animate() {
if(counter == 10) {
counter = 0;
cap.retrieve(frameRGB);
// auto thing = sf::seconds(1);
// sf::sleep(thing);
// auto thing = sf::seconds(1);
// sf::sleep(thing);
//cv::cvtColor(frameRGB,frameRGBA,cv::COLOR_BGR2RGBA);
//std::cout << "FUCK" << std::endl;
IplImage opencvimg2 = (IplImage)frameRGB;
IplImage* opencvimg = &opencvimg2;
SDL_Surface * frameSurface = SDL_CreateRGBSurfaceFrom(
(void*)opencvimg->imageData,
opencvimg->width, opencvimg->height,
opencvimg->depth*opencvimg->nChannels,
opencvimg->widthStep,
0xff0000, 0x00ff00, 0x0000ff, 0);
//std::cout << "FUCK" << std::endl;
SDL_Texture * vidframe = SDL_CreateTextureFromSurface(renderer, frameSurface);
SDL_FreeSurface(frameSurface);
//std::cout << "FUCK2" << std::endl;
SDL_DestroyTexture(textures[0]);
textures[0] = vidframe;
}
else {
counter += 1;
}
}
bool isClose(Vector2D) {
return false;
}
};