diff --git a/CMakeLists.txt b/CMakeLists.txt index c63445b..b700e3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,7 +119,8 @@ set( include/sv_mot.h include/sv_color_line.h include/sv_veri_det.h - include/sv_video_input.h + # include/sv_video_input.h + include/sv_camera.h include/sv_video_output.h include/sv_world.h ) diff --git a/include/sv_video_base.h b/include/sv_video_base.h index 55e1519..390bcf7 100644 --- a/include/sv_video_base.h +++ b/include/sv_video_base.h @@ -326,59 +326,59 @@ protected: }; -enum class CameraType {NONE, WEBCAM, V4L2CAM, G1, Q10, MIPI, GX40}; +// enum class CameraType {NONE, WEBCAM, V4L2CAM, G1, Q10, MIPI, GX40}; -class CameraBase { -public: - CameraBase(CameraType type=CameraType::NONE, int id=0); - ~CameraBase(); - void open(CameraType type=CameraType::WEBCAM, int id=0); - bool read(cv::Mat& image); - void release(); +// class CameraBase { +// public: +// CameraBase(CameraType type=CameraType::NONE, int id=0); +// ~CameraBase(); +// void open(CameraType type=CameraType::WEBCAM, int id=0); +// bool read(cv::Mat& image); +// void release(); - int getW(); - int getH(); - int getFps(); - std::string getIp(); - int getPort(); - double getBrightness(); - double getContrast(); - double getSaturation(); - double getHue(); - double getExposure(); - bool isRunning(); - void setWH(int width, int height); - void setFps(int fps); - void setIp(std::string ip); - void setPort(int port); - void setBrightness(double brightness); - void setContrast(double contrast); - void setSaturation(double saturation); - void setHue(double hue); - void setExposure(double exposure); -protected: - virtual void openImpl(); - void _run(); +// int getW(); +// int getH(); +// int getFps(); +// std::string getIp(); +// int getPort(); +// double getBrightness(); +// double getContrast(); +// double getSaturation(); +// double getHue(); +// double getExposure(); +// bool isRunning(); +// void setWH(int width, int height); +// void setFps(int fps); +// void setIp(std::string ip); +// void setPort(int port); +// void setBrightness(double brightness); +// void setContrast(double contrast); +// void setSaturation(double saturation); +// void setHue(double hue); +// void setExposure(double exposure); +// protected: +// virtual void openImpl(); +// void _run(); - bool _is_running; - bool _is_updated; - std::thread _tt; - cv::VideoCapture _cap; - cv::Mat _frame; - CameraType _type; - int _camera_id; +// bool _is_running; +// bool _is_updated; +// std::thread _tt; +// cv::VideoCapture _cap; +// cv::Mat _frame; +// CameraType _type; +// int _camera_id; - int _width; - int _height; - int _fps; - std::string _ip; - int _port; - double _brightness; - double _contrast; - double _saturation; - double _hue; - double _exposure; -}; +// int _width; +// int _height; +// int _fps; +// std::string _ip; +// int _port; +// double _brightness; +// double _contrast; +// double _saturation; +// double _hue; +// double _exposure; +// }; void drawTargetsInFrame( diff --git a/include/sv_video_input.h b/include/sv_video_input.h index 600d878..29b9076 100644 --- a/include/sv_video_input.h +++ b/include/sv_video_input.h @@ -1,3 +1,4 @@ +#if 0 #ifndef __SV_VIDEO_INPUT__ #define __SV_VIDEO_INPUT__ @@ -25,3 +26,4 @@ protected: } #endif +#endif diff --git a/samples/calib/calibrate_camera_charuco.cpp b/samples/calib/calibrate_camera_charuco.cpp index 8827404..1b74c80 100644 --- a/samples/calib/calibrate_camera_charuco.cpp +++ b/samples/calib/calibrate_camera_charuco.cpp @@ -39,6 +39,8 @@ the use of this software, even if advised of the possibility of such damage. #include #include "aruco_samples_utility.hpp" +#include "sv_camera.h" + using namespace std; using namespace cv; @@ -146,10 +148,14 @@ int main(int argc, char *argv[]) { } // VideoCapture inputVideo; - sv::Camera inputVideo; + sv::Camera inputVideo(c_type); + inputVideo.setIndex(camId); + inputVideo.setStream("192.168.144.64",554); + inputVideo.setWH(imW, imH); inputVideo.setFps(fps); - inputVideo.open(c_type, camId); + + inputVideo.open(); int waitTime = 10; diff --git a/samples/demo/aruco_detection.cpp b/samples/demo/aruco_detection.cpp index 0229400..7b8eb9a 100644 --- a/samples/demo/aruco_detection.cpp +++ b/samples/demo/aruco_detection.cpp @@ -2,6 +2,7 @@ #include // 包含SpireCV SDK头文件 #include +#include "sv_camera.h" using namespace std; @@ -12,10 +13,12 @@ int main(int argc, char *argv[]) { ad.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml"); // 打开摄像头 - sv::Camera cap; - // cap.setWH(640, 480); + sv::Camera cap(sv::CameraType::WEBCAM); + + cap.setIndex(0); + cap.setWH(ad.image_width, ad.image_height); // cap.setFps(30); - cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 + cap.open(); // CameraID 0 // 实例化OpenCV的Mat类,用于内存单帧图像 cv::Mat img; int frame_id = 0; diff --git a/samples/demo/camera_reading.cpp b/samples/demo/camera_reading.cpp index e3ac844..a2a7433 100644 --- a/samples/demo/camera_reading.cpp +++ b/samples/demo/camera_reading.cpp @@ -2,15 +2,17 @@ #include // 包含SpireCV SDK头文件 #include +#include "sv_camera.h" using namespace std; int main(int argc, char *argv[]) { // 打开摄像头 - sv::Camera cap; + sv::Camera cap(sv::CameraType::WEBCAM); + cap.setIndex(0); // cap.setWH(640, 480); // cap.setFps(30); - cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 + cap.open(); // CameraID 0 // 实例化OpenCV的Mat类,用于内存单帧图像 cv::Mat img; while (1) diff --git a/samples/demo/color_line_detect.cpp b/samples/demo/color_line_detect.cpp index 36c72b2..5b19abb 100644 --- a/samples/demo/color_line_detect.cpp +++ b/samples/demo/color_line_detect.cpp @@ -2,6 +2,7 @@ #include // 包含SpireCV SDK头文件 #include +#include "sv_camera.h" using namespace std; using namespace sv; @@ -14,10 +15,11 @@ int main(int argc, char *argv[]) cld.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml"); // 打开摄像头 - sv::Camera cap; - cap.setWH(640, 480); + sv::Camera cap(sv::CameraType::WEBCAM); + cap.setIndex(0); + cap.setWH(cld.image_width, cld.image_height); // cap.setFps(30); - cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 + cap.open(); // CameraID 0 // 实例化OpenCV的Mat类,用于内存单帧图像 cv::Mat img; int frame_id = 0; diff --git a/samples/demo/common_object_detection.cpp b/samples/demo/common_object_detection.cpp index f051756..0b3cf80 100644 --- a/samples/demo/common_object_detection.cpp +++ b/samples/demo/common_object_detection.cpp @@ -2,6 +2,7 @@ #include // 包含SpireCV SDK头文件 #include +#include "sv_camera.h" using namespace std; @@ -12,10 +13,11 @@ int main(int argc, char *argv[]) { cod.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml"); // 打开摄像头 - sv::Camera cap; - // cap.setWH(640, 480); + sv::Camera cap(sv::CameraType::WEBCAM); + cap.setIndex(0); + cap.setWH(cod.image_width, cod.image_height); // cap.setFps(30); - cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 + cap.open(); // CameraID 0 // 实例化OpenCV的Mat类,用于内存单帧图像 cv::Mat img; int frame_id = 0; diff --git a/samples/demo/detection_with_clicked_tracking.cpp b/samples/demo/detection_with_clicked_tracking.cpp index 7a779a4..ab4e91a 100644 --- a/samples/demo/detection_with_clicked_tracking.cpp +++ b/samples/demo/detection_with_clicked_tracking.cpp @@ -2,6 +2,7 @@ #include // 包含SpireCV SDK头文件 #include +#include "sv_camera.h" using namespace std; @@ -48,10 +49,11 @@ int main(int argc, char *argv[]) { // 打开摄像头 - sv::Camera cap; - // cap.setWH(640, 480); + sv::Camera cap(sv::CameraType::WEBCAM); + cap.setIndex(0); + cap.setWH(cod.image_width, cod.image_height); // cap.setFps(30); - cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 + cap.open(); // CameraID 0 // 实例化OpenCV的Mat类,用于内存单帧图像 cv::Mat img; diff --git a/samples/demo/ellipse_detection.cpp b/samples/demo/ellipse_detection.cpp index 596bf2f..fbcccff 100644 --- a/samples/demo/ellipse_detection.cpp +++ b/samples/demo/ellipse_detection.cpp @@ -2,6 +2,7 @@ #include // 包含SpireCV SDK头文件 #include +#include "sv_camera.h" using namespace std; @@ -12,10 +13,12 @@ int main(int argc, char *argv[]) { ed.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml"); // 打开摄像头 - sv::Camera cap; - // cap.setWH(640, 480); + sv::Camera cap(sv::CameraType::WEBCAM); + cap.setIndex(0); + cap.setWH(ed.image_width, ed.image_height); // cap.setFps(30); - cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 + cap.open(); // CameraID 0 + // 实例化OpenCV的Mat类,用于内存单帧图像 cv::Mat img; int frame_id = 0; diff --git a/samples/demo/gimbal_detection_with_clicked_tracking.cpp b/samples/demo/gimbal_detection_with_clicked_tracking.cpp index a7c6623..9247685 100644 --- a/samples/demo/gimbal_detection_with_clicked_tracking.cpp +++ b/samples/demo/gimbal_detection_with_clicked_tracking.cpp @@ -3,6 +3,7 @@ // 包含SpireCV SDK头文件 #include #include +#include "sv_camera.h" // 定义窗口名称 static const std::string RGB_WINDOW = "Image window"; @@ -34,27 +35,6 @@ void gimbalNoTrack(void) int main(int argc, char *argv[]) { - // 实例化吊舱 - gimbal = new sv::Gimbal(sv::GimbalType::G1, sv::GimbalLink::SERIAL); - // 使用 /dev/ttyUSB0 作为控制串口 - gimbal->setSerialPort("/dev/ttyUSB0"); - // 以GimableCallback作为状态回调函数启用吊舱控制 - gimbal->open(GimableCallback); - // 定义相机 - sv::Camera cap; - // 设置相机流媒体地址为 192.168.2.64 - cap.setIp("192.168.2.64"); - // 设置获取画面分辨率为720P - cap.setWH(1280, 720); - // 设置视频帧率为30帧 - cap.setFps(30); - // 开启相机 - cap.open(sv::CameraType::G1); - - // 定义一个新的窗口,可在上面进行框选操作 - cv::namedWindow(RGB_WINDOW); - // 设置窗口操作回调函数,该函数实现整个框选逻辑 - cv::setMouseCallback(RGB_WINDOW, onMouse, 0); // 实例化 框选目标跟踪类 sv::SingleObjectTracker sot; // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 @@ -63,6 +43,37 @@ int main(int argc, char *argv[]) sv::CommonObjectDetector cod; cod.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1280x720.yaml"); + // 实例化吊舱 + gimbal = new sv::Gimbal(sv::GimbalType::G1, sv::GimbalLink::SERIAL); + // 使用 /dev/ttyUSB0 作为控制串口 + gimbal->setSerialPort("/dev/ttyUSB0"); + // 以GimableCallback作为状态回调函数启用吊舱控制 + gimbal->open(GimableCallback); + + // 打开摄像头 + sv::Camera cap(sv::CameraType::G1); + cap.setStream("192.168.2.64",554); + cap.setWH(cod.image_width, cod.image_height); + cap.setFps(30); + cap.open(); // CameraID 0 + + // // 定义相机 + // sv::Camera cap; + // // 设置相机流媒体地址为 192.168.2.64 + // cap.setIp("192.168.2.64"); + // // 设置获取画面分辨率为720P + // cap.setWH(1280, 720); + // // 设置视频帧率为30帧 + // cap.setFps(30); + // // 开启相机 + // cap.open(sv::CameraType::G1); + + // 定义一个新的窗口,可在上面进行框选操作 + cv::namedWindow(RGB_WINDOW); + // 设置窗口操作回调函数,该函数实现整个框选逻辑 + cv::setMouseCallback(RGB_WINDOW, onMouse, 0); + + // 实例化OpenCV的Mat类,用于内存单帧图像 cv::Mat img; int frame_id = 0; diff --git a/samples/demo/gimbal_landing_marker_detection.cpp b/samples/demo/gimbal_landing_marker_detection.cpp index f6e0357..af8f690 100644 --- a/samples/demo/gimbal_landing_marker_detection.cpp +++ b/samples/demo/gimbal_landing_marker_detection.cpp @@ -3,6 +3,7 @@ // 包含SpireCV SDK头文件 #include // #include "gimbal_tools.hpp" +#include "sv_camera.h" using namespace std; @@ -33,32 +34,40 @@ void gimbalNoTrack(void) } int main(int argc, char *argv[]) -{ +{ + // 实例化 圆形降落标志 检测器类 + sv::LandingMarkerDetector lmd; + // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 + lmd.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1280x720.yaml"); // 实例化吊舱 gimbal = new sv::Gimbal(sv::GimbalType::G1, sv::GimbalLink::SERIAL); // 使用 /dev/ttyUSB0 作为控制串口 gimbal->setSerialPort("/dev/ttyUSB0"); // 以GimableCallback作为状态回调函数启用吊舱控制 gimbal->open(GimableCallback); - // 定义相机 - sv::Camera cap; - // 设置相机流媒体地址为 192.168.2.64 - cap.setIp("192.168.2.64"); - // 设置获取画面分辨率为720P - cap.setWH(1280, 720); - // 设置视频帧率为30帧 + + // 打开摄像头 + sv::Camera cap(sv::CameraType::G1); + cap.setStream("192.168.2.64", 554); + cap.setWH(lmd.image_width, lmd.image_height); cap.setFps(30); - // 开启相机 - cap.open(sv::CameraType::G1); + cap.open(); // CameraID 0 + + // // 定义相机 + // sv::Camera cap; + // // 设置相机流媒体地址为 192.168.2.64 + // cap.setIp("192.168.2.64"); + // // 设置获取画面分辨率为720P + // cap.setWH(1280, 720); + // // 设置视频帧率为30帧 + // cap.setFps(30); + // // 开启相机 + // cap.open(sv::CameraType::G1); // 定义一个窗口 才可以在上面操作 cv::namedWindow(RGB_WINDOW); // 设置窗口操作回调函数,该函数实现吊舱控制 cv::setMouseCallback(RGB_WINDOW, onMouse, 0); - // 实例化 圆形降落标志 检测器类 - sv::LandingMarkerDetector lmd; - // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 - lmd.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1280x720.yaml"); // 实例化OpenCV的Mat类,用于内存单帧图像 cv::Mat img; diff --git a/samples/demo/gimbal_udp_detection_info_sender.cpp b/samples/demo/gimbal_udp_detection_info_sender.cpp index f9ee0a8..b253a3b 100644 --- a/samples/demo/gimbal_udp_detection_info_sender.cpp +++ b/samples/demo/gimbal_udp_detection_info_sender.cpp @@ -2,6 +2,7 @@ #include // 包含SpireCV SDK头文件 #include +#include "sv_camera.h" using namespace std; @@ -42,32 +43,41 @@ static const std::string RGB_WINDOW = "Image window"; void onMouse(int event, int x, int y, int, void *); int main(int argc, char *argv[]) -{ +{ + // 实例化Aruco检测器类 + sv::ArucoDetector ad; + // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 + ad.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1280x720.yaml"); // 实例化吊舱 gimbal = new sv::Gimbal(sv::GimbalType::G1, sv::GimbalLink::SERIAL); // 使用 /dev/ttyUSB0 作为控制串口 gimbal->setSerialPort("/dev/ttyUSB0"); // 以gimableCallback作为状态回调函数启用吊舱控制 gimbal->open(gimableCallback); - // 定义相机 - sv::Camera cap; - // 设置相机流媒体地址为 192.168.2.64 - cap.setIp("192.168.2.64"); - // 设置获取画面分辨率为720P - cap.setWH(1280, 720); - // 设置视频帧率为30帧 + + // 打开摄像头 + sv::Camera cap(sv::CameraType::G1); + cap.setStream("192.168.2.64",554); + cap.setWH(ad.image_width, ad.image_height); cap.setFps(30); - // 开启相机 - cap.open(sv::CameraType::G1); + cap.open(); // CameraID 0 + + // // 定义相机 + // sv::Camera cap; + // // 设置相机流媒体地址为 192.168.2.64 + // cap.setIp("192.168.2.64"); + // // 设置获取画面分辨率为720P + // cap.setWH(1280, 720); + // // 设置视频帧率为30帧 + // cap.setFps(30); + // // 开启相机 + // cap.open(sv::CameraType::G1); // 定义一个窗口 才可以在上面操作 cv::namedWindow(RGB_WINDOW); // 设置窗口操作回调函数,该函数实现吊舱控制 cv::setMouseCallback(RGB_WINDOW, onMouse, 0); - // 实例化Aruco检测器类 - sv::ArucoDetector ad; - // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 - ad.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1280x720.yaml"); + sv::UDPServer udp; // 实例化OpenCV的Mat类,用于内存单帧图像 diff --git a/samples/demo/landing_marker_detection.cpp b/samples/demo/landing_marker_detection.cpp index ab36c2d..335efac 100644 --- a/samples/demo/landing_marker_detection.cpp +++ b/samples/demo/landing_marker_detection.cpp @@ -2,7 +2,7 @@ #include // 包含SpireCV SDK头文件 #include - +#include "sv_camera.h" using namespace std; int main(int argc, char *argv[]) { @@ -11,11 +11,13 @@ int main(int argc, char *argv[]) { // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 lmd.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml"); - // 打开摄像头 - sv::Camera cap; - // cap.setWH(640, 480); + // 打开摄像头 + sv::Camera cap(sv::CameraType::WEBCAM); + cap.setIndex(0); + cap.setWH(lmd.image_width, lmd.image_height); // cap.setFps(30); - cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 + cap.open(); // CameraID 0 + // 实例化OpenCV的Mat类,用于内存单帧图像 cv::Mat img; int frame_id = 0; diff --git a/samples/demo/multiple_object_tracking.cpp b/samples/demo/multiple_object_tracking.cpp index a61e5f0..d0d706a 100644 --- a/samples/demo/multiple_object_tracking.cpp +++ b/samples/demo/multiple_object_tracking.cpp @@ -2,6 +2,7 @@ #include // 包含SpireCV SDK头文件 #include +#include "sv_camera.h" using namespace std; @@ -15,11 +16,13 @@ int main(int argc, char *argv[]) { mot.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml"); mot.init(&cod); - // 打开摄像头 - sv::Camera cap; - // cap.setWH(640, 480); + // 打开摄像头 + sv::Camera cap(sv::CameraType::WEBCAM); + cap.setIndex(0); + cap.setWH(cod.image_width, cod.image_height); // cap.setFps(30); - cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 + cap.open(); // CameraID 0 + // 实例化OpenCV的Mat类,用于内存单帧图像 cv::Mat img; int frame_id = 0; diff --git a/samples/demo/single_object_tracking.cpp b/samples/demo/single_object_tracking.cpp index ee4741f..80676b3 100644 --- a/samples/demo/single_object_tracking.cpp +++ b/samples/demo/single_object_tracking.cpp @@ -2,7 +2,7 @@ #include // 包含SpireCV SDK头文件 #include - +#include "sv_camera.h" using namespace std; // 定义窗口名称 @@ -32,11 +32,13 @@ int main(int argc, char *argv[]) { // sot.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1280x720.yaml"); // sot.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1920x1080.yaml"); - // 打开摄像头 - sv::Camera cap; - // cap.setWH(640, 480); + // 打开摄像头 + sv::Camera cap(sv::CameraType::WEBCAM); + cap.setIndex(0); + cap.setWH(sot.image_width, sot.image_height); // cap.setFps(30); - cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 + cap.open(); // CameraID 0 + // cv::VideoCapture cap("/home/amov/SpireCV/test/tracking_1280x720.mp4"); // 实例化OpenCV的Mat类,用于内存单帧图像 cv::Mat img; diff --git a/samples/demo/udp_detection_info_sender.cpp b/samples/demo/udp_detection_info_sender.cpp index cd25812..eff356a 100644 --- a/samples/demo/udp_detection_info_sender.cpp +++ b/samples/demo/udp_detection_info_sender.cpp @@ -2,7 +2,7 @@ #include // 包含SpireCV SDK头文件 #include - +#include "sv_camera.h" using namespace std; int main(int argc, char *argv[]) { @@ -11,11 +11,12 @@ int main(int argc, char *argv[]) { // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 ad.loadCameraParams("/home/amov/SpireCV/calib_webcam_640x480.yaml"); - // 打开摄像头 - sv::Camera cap; - cap.setWH(640, 480); - cap.setFps(30); - cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 + // 打开摄像头 + sv::Camera cap(sv::CameraType::WEBCAM); + cap.setIndex(0); + cap.setWH(ad.image_width, ad.image_height); + // cap.setFps(30); + cap.open(); // CameraID 0 sv::UDPServer udp; // 实例化OpenCV的Mat类,用于内存单帧图像 diff --git a/samples/demo/veri.cpp b/samples/demo/veri.cpp index 96caf74..6b5d281 100644 --- a/samples/demo/veri.cpp +++ b/samples/demo/veri.cpp @@ -2,7 +2,7 @@ #include // 包含SpireCV SDK头文件 #include - +#include "sv_camera.h" using namespace std; struct node @@ -25,11 +25,12 @@ int main(int argc, char *argv[]) sv::CommonObjectDetector cod; cod.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml"); - // 打开摄像头 - sv::Camera cap; - // cap.setWH(640, 480); + // 打开摄像头 + sv::Camera cap(sv::CameraType::WEBCAM); + cap.setIndex(0); + cap.setWH(cod.image_width, cod.image_height); // cap.setFps(30); - cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 + cap.open(); // CameraID 0 // 实例化OpenCV的Mat类,用于内存单帧图像 cv::Mat img; int frame_id = 0; diff --git a/samples/demo/video_saving.cpp b/samples/demo/video_saving.cpp index d4f7414..afb84fa 100644 --- a/samples/demo/video_saving.cpp +++ b/samples/demo/video_saving.cpp @@ -2,7 +2,7 @@ #include // 包含SpireCV SDK头文件 #include - +#include "sv_camera.h" using namespace std; int main(int argc, char *argv[]) { @@ -12,10 +12,12 @@ int main(int argc, char *argv[]) { cod.loadCameraParams("/home/amov/SpireCV/calib_webcam_640x480.yaml"); // 打开摄像头 - sv::Camera cap; - // cap.setWH(640, 480); + // 打开摄像头 + sv::Camera cap(sv::CameraType::WEBCAM); + cap.setIndex(0); + cap.setWH(cod.image_width, cod.image_height); // cap.setFps(30); - cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 + cap.open(); // CameraID 0 // 实例化OpenCV的Mat类,用于内存单帧图像 cv::Mat img; int frame_id = 0; diff --git a/samples/demo/video_streaming.cpp b/samples/demo/video_streaming.cpp index 406b5b2..6f83b7d 100644 --- a/samples/demo/video_streaming.cpp +++ b/samples/demo/video_streaming.cpp @@ -2,15 +2,17 @@ #include // 包含SpireCV SDK头文件 #include +#include "sv_camera.h" using namespace std; int main(int argc, char *argv[]) { - // 打开摄像头 - sv::Camera cap; - // cap.setWH(1280, 720); - // cap.setFps(30); - cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 + // 打开摄像头 + sv::Camera cap(sv::CameraType::WEBCAM); + cap.setIndex(0); + cap.setWH(1280, 720); + cap.setFps(30); + cap.open(); // CameraID 0 // 实例化视频推流类sv::VideoStreamer sv::VideoStreamer streamer; diff --git a/samples/test/gimbal_test.cpp b/samples/test/gimbal_test.cpp index 0db3de6..969d875 100644 --- a/samples/test/gimbal_test.cpp +++ b/samples/test/gimbal_test.cpp @@ -3,6 +3,7 @@ // 包含SpireCV SDK头文件 #include #include +#include "sv_camera.h" // yaw roll pitch double gimbalEulerAngle[3]; @@ -143,14 +144,20 @@ int main(int argc, char *argv[]) std::cout << " pass... " << std::endl; std::cout << " start image test " << std::endl; - sv::Camera cap; - cap.setIp(argv[2]); + // 打开摄像头 + sv::Camera cap(sv::CameraType::G1); + cap.setStream(argv[2], 554); cap.setWH(1280, 720); cap.setFps(30); + cap.open(); // CameraID 0 - cap.open(sv::CameraType::G1); + // sv::Camera cap; + // cap.setIp(argv[2]); + // cap.setWH(1280, 720); + // cap.setFps(30); + // cap.open(sv::CameraType::G1); - if (!cap.isRunning()) + if (!cap.isActive()) { std::cout << " gimbal image error , failed !!!!!" << std::endl; return -1; diff --git a/video_io/driver/sv_camera_G1.cpp b/video_io/driver/sv_camera_G1.cpp index bb71df0..a675edb 100644 --- a/video_io/driver/sv_camera_G1.cpp +++ b/video_io/driver/sv_camera_G1.cpp @@ -1,12 +1,12 @@ /* - * @Description: G1相机的具体功能实现 + * @Description: * @Author: L LC @amov * @Date: 2023-12-19 18:30:17 * @LastEditors: L LC @amov - * @LastEditTime: 2023-12-21 11:42:40 + * @LastEditTime: 2023-12-21 17:56:47 * @FilePath: /SpireCV/video_io/driver/sv_camera_G1.cpp */ -#include "../sv_camera_privately.h" +#include "sv_camera_privately.h" #include class sv_camera_G1 : public sv_p::CameraBase @@ -44,13 +44,6 @@ bool sv_camera_G1::setStream(const std::string &ip, uint16_t port) return ret; } -// 合法的输入尺寸列表 -const static std::vector imageSizeList[3] = - { - {1520, 2704}, - {1080, 1920}, - {720, 1280}}; - const static uint32_t imageHList[3] = {1520, 1080, 720}; const static uint32_t imageWList[3] = {2704, 1920, 1280}; diff --git a/video_io/driver/sv_camera_GX40.cpp b/video_io/driver/sv_camera_GX40.cpp index 7ebe63e..52c10db 100644 --- a/video_io/driver/sv_camera_GX40.cpp +++ b/video_io/driver/sv_camera_GX40.cpp @@ -3,10 +3,10 @@ * @Author: L LC @amov * @Date: 2023-12-19 18:30:17 * @LastEditors: L LC @amov - * @LastEditTime: 2023-12-21 17:27:22 + * @LastEditTime: 2023-12-21 17:57:02 * @FilePath: /SpireCV/video_io/driver/sv_camera_GX40.cpp */ -#include "../sv_camera_privately.h" +#include "sv_camera_privately.h" #include class sv_camera_GX40 : public sv_p::CameraBase diff --git a/video_io/driver/sv_camera_MC1.cpp b/video_io/driver/sv_camera_MC1.cpp index c8ad8a8..22a2749 100644 --- a/video_io/driver/sv_camera_MC1.cpp +++ b/video_io/driver/sv_camera_MC1.cpp @@ -3,10 +3,10 @@ * @Author: L LC @amov * @Date: 2023-12-19 18:30:17 * @LastEditors: L LC @amov - * @LastEditTime: 2023-12-21 17:10:30 + * @LastEditTime: 2023-12-21 17:57:07 * @FilePath: /SpireCV/video_io/driver/sv_camera_MC1.cpp */ -#include "../sv_camera_privately.h" +#include "sv_camera_privately.h" #include class sv_camera_MC1 : public sv_p::CameraBase diff --git a/video_io/driver/sv_camera_V4L2s.cpp b/video_io/driver/sv_camera_V4L2s.cpp index 62d13f3..2141306 100644 --- a/video_io/driver/sv_camera_V4L2s.cpp +++ b/video_io/driver/sv_camera_V4L2s.cpp @@ -3,10 +3,10 @@ * @Author: L LC @amov * @Date: 2023-12-21 10:45:50 * @LastEditors: L LC @amov - * @LastEditTime: 2023-12-21 11:26:43 + * @LastEditTime: 2023-12-21 17:57:30 * @FilePath: /SpireCV/video_io/driver/sv_camera_V4L2s.cpp */ -#include "../sv_camera_privately.h" +#include "sv_camera_privately.h" class sv_camera_V4L2 : public sv_p::CameraBase { diff --git a/video_io/driver/sv_camera_file.cpp b/video_io/driver/sv_camera_file.cpp index 6ad51db..8b16ebf 100644 --- a/video_io/driver/sv_camera_file.cpp +++ b/video_io/driver/sv_camera_file.cpp @@ -3,10 +3,10 @@ * @Author: L LC @amov * @Date: 2023-12-21 11:30:40 * @LastEditors: L LC @amov - * @LastEditTime: 2023-12-21 11:43:08 + * @LastEditTime: 2023-12-21 17:56:34 * @FilePath: /SpireCV/video_io/driver/sv_camera_file.cpp */ -#include "../sv_camera_privately.h" +#include "sv_camera_privately.h" class sv_camera_FILE : public sv_p::CameraBase { diff --git a/video_io/driver/sv_camera_mipi.cpp b/video_io/driver/sv_camera_mipi.cpp index 2340d58..0d73c56 100644 --- a/video_io/driver/sv_camera_mipi.cpp +++ b/video_io/driver/sv_camera_mipi.cpp @@ -1,12 +1,12 @@ /* - * @Description: G1相机的具体功能实现 + * @Description: * @Author: L LC @amov * @Date: 2023-12-19 18:30:17 * @LastEditors: L LC @amov - * @LastEditTime: 2023-12-21 14:40:30 + * @LastEditTime: 2023-12-21 17:57:12 * @FilePath: /SpireCV/video_io/driver/sv_camera_mipi.cpp */ -#include "../sv_camera_privately.h" +#include "sv_camera_privately.h" #include class sv_camera_MIPI : public sv_p::CameraBase diff --git a/video_io/driver/sv_camera_streaming.cpp b/video_io/driver/sv_camera_streaming.cpp index 5273852..23099bf 100644 --- a/video_io/driver/sv_camera_streaming.cpp +++ b/video_io/driver/sv_camera_streaming.cpp @@ -3,10 +3,10 @@ * @Author: L LC @amov * @Date: 2023-12-21 11:30:40 * @LastEditors: L LC @amov - * @LastEditTime: 2023-12-21 11:43:16 + * @LastEditTime: 2023-12-21 17:57:22 * @FilePath: /SpireCV/video_io/driver/sv_camera_streaming.cpp */ -#include "../sv_camera_privately.h" +#include "sv_camera_privately.h" class sv_camera_Streaming : public sv_p::CameraBase { diff --git a/video_io/sv_video_base.cpp b/video_io/sv_video_base.cpp index 3a78973..1b88155 100644 --- a/video_io/sv_video_base.cpp +++ b/video_io/sv_video_base.cpp @@ -969,172 +969,172 @@ void VideoWriterBase::releaseImpl() } -CameraBase::CameraBase(CameraType type, int id) -{ - this->_is_running = false; - this->_is_updated = false; - this->_type = type; +// CameraBase::CameraBase(CameraType type, int id) +// { +// this->_is_running = false; +// this->_is_updated = false; +// this->_type = type; - this->_width = -1; - this->_height = -1; - this->_fps = -1; - this->_ip = "192.168.2.64"; - this->_port = -1; - this->_brightness = -1; - this->_contrast = -1; - this->_saturation = -1; - this->_hue = -1; - this->_exposure = -1; +// this->_width = -1; +// this->_height = -1; +// this->_fps = -1; +// this->_ip = "192.168.2.64"; +// this->_port = -1; +// this->_brightness = -1; +// this->_contrast = -1; +// this->_saturation = -1; +// this->_hue = -1; +// this->_exposure = -1; - this->open(type, id); -} -CameraBase::~CameraBase() -{ - this->_is_running = false; - // this->_tt.join(); -} -void CameraBase::setWH(int width, int height) -{ - this->_width = width; - this->_height = height; -} -void CameraBase::setFps(int fps) -{ - this->_fps = fps; -} -void CameraBase::setIp(std::string ip) -{ - this->_ip = ip; -} -void CameraBase::setPort(int port) -{ - this->_port = port; -} -void CameraBase::setBrightness(double brightness) -{ - this->_brightness = brightness; -} -void CameraBase::setContrast(double contrast) -{ - this->_contrast = contrast; -} -void CameraBase::setSaturation(double saturation) -{ - this->_saturation = saturation; -} -void CameraBase::setHue(double hue) -{ - this->_hue = hue; -} -void CameraBase::setExposure(double exposure) -{ - this->_exposure = exposure; -} +// this->open(type, id); +// } +// CameraBase::~CameraBase() +// { +// this->_is_running = false; +// // this->_tt.join(); +// } +// void CameraBase::setWH(int width, int height) +// { +// this->_width = width; +// this->_height = height; +// } +// void CameraBase::setFps(int fps) +// { +// this->_fps = fps; +// } +// void CameraBase::setIp(std::string ip) +// { +// this->_ip = ip; +// } +// void CameraBase::setPort(int port) +// { +// this->_port = port; +// } +// void CameraBase::setBrightness(double brightness) +// { +// this->_brightness = brightness; +// } +// void CameraBase::setContrast(double contrast) +// { +// this->_contrast = contrast; +// } +// void CameraBase::setSaturation(double saturation) +// { +// this->_saturation = saturation; +// } +// void CameraBase::setHue(double hue) +// { +// this->_hue = hue; +// } +// void CameraBase::setExposure(double exposure) +// { +// this->_exposure = exposure; +// } -int CameraBase::getW() -{ - return this->_width; -} -int CameraBase::getH() -{ - return this->_height; -} -int CameraBase::getFps() -{ - return this->_fps; -} -std::string CameraBase::getIp() -{ - return this->_ip; -} -int CameraBase::getPort() -{ - return this->_port; -} -double CameraBase::getBrightness() -{ - return this->_brightness; -} -double CameraBase::getContrast() -{ - return this->_contrast; -} -double CameraBase::getSaturation() -{ - return this->_saturation; -} -double CameraBase::getHue() -{ - return this->_hue; -} -double CameraBase::getExposure() -{ - return this->_exposure; -} -bool CameraBase::isRunning() -{ - return this->_is_running; -} +// int CameraBase::getW() +// { +// return this->_width; +// } +// int CameraBase::getH() +// { +// return this->_height; +// } +// int CameraBase::getFps() +// { +// return this->_fps; +// } +// std::string CameraBase::getIp() +// { +// return this->_ip; +// } +// int CameraBase::getPort() +// { +// return this->_port; +// } +// double CameraBase::getBrightness() +// { +// return this->_brightness; +// } +// double CameraBase::getContrast() +// { +// return this->_contrast; +// } +// double CameraBase::getSaturation() +// { +// return this->_saturation; +// } +// double CameraBase::getHue() +// { +// return this->_hue; +// } +// double CameraBase::getExposure() +// { +// return this->_exposure; +// } +// bool CameraBase::isRunning() +// { +// return this->_is_running; +// } -void CameraBase::openImpl() -{ +// void CameraBase::openImpl() +// { -} -void CameraBase::open(CameraType type, int id) -{ - this->_type = type; - this->_camera_id = id; +// } +// void CameraBase::open(CameraType type, int id) +// { +// this->_type = type; +// this->_camera_id = id; - openImpl(); +// openImpl(); - if (this->_cap.isOpened()) - { - std::cout << "Camera opened!" << std::endl; - this->_is_running = true; - this->_tt = std::thread(&CameraBase::_run, this); - this->_tt.detach(); - } - else if (type != CameraType::NONE) - { - std::cout << "Camera can NOT open!" << std::endl; - } -} -void CameraBase::_run() -{ - while (this->_is_running && this->_cap.isOpened()) - { - this->_cap >> this->_frame; - this->_is_updated = true; - std::this_thread::sleep_for(std::chrono::milliseconds(2)); - } -} -bool CameraBase::read(cv::Mat& image) -{ - if (this->_type != CameraType::NONE) - { - int n_try = 0; - while (n_try < 5000) - { - if (this->_is_updated) - { - this->_is_updated = false; - this->_frame.copyTo(image); - break; - } - std::this_thread::sleep_for(std::chrono::milliseconds(20)); - n_try ++; - } - } - if (image.cols == 0 || image.rows == 0) - { - throw std::runtime_error("SpireCV (101) Camera cannot OPEN, check CAMERA_ID!"); - } - return image.cols > 0 && image.rows > 0; -} -void CameraBase::release() -{ - _cap.release(); -} +// if (this->_cap.isOpened()) +// { +// std::cout << "Camera opened!" << std::endl; +// this->_is_running = true; +// this->_tt = std::thread(&CameraBase::_run, this); +// this->_tt.detach(); +// } +// else if (type != CameraType::NONE) +// { +// std::cout << "Camera can NOT open!" << std::endl; +// } +// } +// void CameraBase::_run() +// { +// while (this->_is_running && this->_cap.isOpened()) +// { +// this->_cap >> this->_frame; +// this->_is_updated = true; +// std::this_thread::sleep_for(std::chrono::milliseconds(2)); +// } +// } +// bool CameraBase::read(cv::Mat& image) +// { +// if (this->_type != CameraType::NONE) +// { +// int n_try = 0; +// while (n_try < 5000) +// { +// if (this->_is_updated) +// { +// this->_is_updated = false; +// this->_frame.copyTo(image); +// break; +// } +// std::this_thread::sleep_for(std::chrono::milliseconds(20)); +// n_try ++; +// } +// } +// if (image.cols == 0 || image.rows == 0) +// { +// throw std::runtime_error("SpireCV (101) Camera cannot OPEN, check CAMERA_ID!"); +// } +// return image.cols > 0 && image.rows > 0; +// } +// void CameraBase::release() +// { +// _cap.release(); +// } diff --git a/video_io/sv_video_input.cpp b/video_io/sv_video_input.cpp index 2db1c8d..3b6eb73 100644 --- a/video_io/sv_video_input.cpp +++ b/video_io/sv_video_input.cpp @@ -1,3 +1,4 @@ +#if 0 #include "sv_video_input.h" #include #include @@ -130,3 +131,5 @@ void Camera::openImpl() } } + +#endif \ No newline at end of file