2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2016-10-28 00:54:28 -07:00
|
|
|
|
2017-08-25 17:48:06 -07:00
|
|
|
#include <cstdio>
|
2016-10-28 00:54:28 -07:00
|
|
|
#include <iostream>
|
2017-08-25 17:48:06 -07:00
|
|
|
|
|
|
|
|
#include <opencv2/core/core.hpp>
|
|
|
|
|
|
|
|
|
|
#include "cscore.h"
|
2019-05-30 19:12:05 -07:00
|
|
|
#include "cscore_cv.h"
|
2016-10-28 00:54:28 -07:00
|
|
|
|
|
|
|
|
int main() {
|
2016-12-04 00:08:47 -08:00
|
|
|
cs::UsbCamera camera{"usbcam", 0};
|
2016-10-28 00:54:28 -07:00
|
|
|
camera.SetVideoMode(cs::VideoMode::kMJPEG, 320, 240, 30);
|
2016-12-04 00:08:47 -08:00
|
|
|
cs::MjpegServer mjpegServer{"httpserver", 8081};
|
2016-10-28 00:54:28 -07:00
|
|
|
mjpegServer.SetSource(camera);
|
|
|
|
|
cs::CvSink cvsink{"cvsink"};
|
|
|
|
|
cvsink.SetSource(camera);
|
|
|
|
|
cs::CvSource cvsource{"cvsource", cs::VideoMode::kMJPEG, 320, 240, 30};
|
2016-12-04 00:08:47 -08:00
|
|
|
cs::MjpegServer cvMjpegServer{"cvhttpserver", 8082};
|
2016-10-28 00:54:28 -07:00
|
|
|
cvMjpegServer.SetSource(cvsource);
|
|
|
|
|
|
|
|
|
|
cv::Mat test;
|
|
|
|
|
cv::Mat flip;
|
|
|
|
|
for (;;) {
|
|
|
|
|
uint64_t time = cvsink.GrabFrame(test);
|
2016-12-02 23:43:35 -08:00
|
|
|
if (time == 0) {
|
|
|
|
|
std::cout << "error: " << cvsink.GetError() << std::endl;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2017-08-25 17:48:06 -07:00
|
|
|
std::cout << "got frame at time " << time << " size " << test.size()
|
|
|
|
|
<< std::endl;
|
2016-10-28 00:54:28 -07:00
|
|
|
cv::flip(test, flip, 0);
|
|
|
|
|
cvsource.PutFrame(flip);
|
|
|
|
|
}
|
|
|
|
|
}
|