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 <opencv2/core/core.hpp>
|
|
|
|
|
|
2026-01-04 16:59:02 -08:00
|
|
|
#include "wpi/cs/CvSink.hpp"
|
|
|
|
|
#include "wpi/cs/CvSource.hpp"
|
|
|
|
|
#include "wpi/cs/MjpegServer.hpp"
|
|
|
|
|
#include "wpi/cs/UsbCamera.hpp"
|
2025-11-07 19:57:55 -05:00
|
|
|
#include "wpi/util/print.hpp"
|
2016-10-28 00:54:28 -07:00
|
|
|
|
|
|
|
|
int main() {
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::cs::UsbCamera camera{"usbcam", 0};
|
2026-01-04 16:59:02 -08:00
|
|
|
camera.SetVideoMode(wpi::util::PixelFormat::kMJPEG, 320, 240, 30);
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::cs::MjpegServer mjpegServer{"httpserver", 8081};
|
2016-10-28 00:54:28 -07:00
|
|
|
mjpegServer.SetSource(camera);
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::cs::CvSink cvsink{"cvsink"};
|
2016-10-28 00:54:28 -07:00
|
|
|
cvsink.SetSource(camera);
|
2026-01-04 16:59:02 -08:00
|
|
|
wpi::cs::CvSource cvsource{"cvsource", wpi::util::PixelFormat::kMJPEG, 320,
|
|
|
|
|
240, 30};
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::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) {
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::util::print("error: {}\n", cvsink.GetError());
|
2016-12-02 23:43:35 -08:00
|
|
|
continue;
|
|
|
|
|
}
|
2025-11-07 20:01:58 -05:00
|
|
|
wpi::util::print("got frame at time {} size ({}, {})\n", time,
|
|
|
|
|
test.size().width, test.size().height);
|
2016-10-28 00:54:28 -07:00
|
|
|
cv::flip(test, flip, 0);
|
|
|
|
|
cvsource.PutFrame(flip);
|
|
|
|
|
}
|
|
|
|
|
}
|