diff --git a/GSTtest/GSTtest.vcxproj b/GSTtest/GSTtest.vcxproj new file mode 100644 index 0000000..f452a49 --- /dev/null +++ b/GSTtest/GSTtest.vcxproj @@ -0,0 +1,143 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {BB038458-DFC5-4ACD-96CB-35512801136D} + GSTtest + 10.0 + + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + MultiByte + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + true + + + Console + + + + + Level3 + Disabled + true + true + + + Console + ws2_32.lib;%(AdditionalDependencies) + + + + + Level3 + MaxSpeed + true + true + true + true + + + Console + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + Console + true + true + + + + + + + + + + + + \ No newline at end of file diff --git a/GSTtest/GSTtest.vcxproj.filters b/GSTtest/GSTtest.vcxproj.filters new file mode 100644 index 0000000..215ceec --- /dev/null +++ b/GSTtest/GSTtest.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + ソース ファイル + + + + + ヘッダー ファイル + + + \ No newline at end of file diff --git a/GSTtest/main.cpp b/GSTtest/main.cpp new file mode 100644 index 0000000..bdf20cb --- /dev/null +++ b/GSTtest/main.cpp @@ -0,0 +1,163 @@ +#include +//#include +#include +#include +#include +#include +#include "myOpenCV.h" + +using namespace std; + +void keep_alive_timer(string keep_alive_message); +void udp_socket_stream(); +void VideoStream(); + +//#define ADDR "192.168.71.50" +#define ADDR "192.168.23.158" +#define V6_ADDR "fe80::76fe:48ff:fe3c:518c" +//const string SERVER = "192.168.71.50"; //ip address of udp server +const string SERVER = ADDR; //ip address of udp server +const string KA_DATA_MSG = "{\"type\": \"live.data.unicast\", \"key\": \"some_GUID\", \"op\": \"start\"}"; +const int BUFLEN = 512; //Max length of buffer +const int PORT = 49152; //The port on which to listen for incoming data +struct sockaddr_in si_other; +SOCKET s; + +int data_stream_main() +{ + printf("TOBII GLASSES 2 exampel in c++ \n"); + + + WSAData data; + int err = WSAStartup(MAKEWORD(2, 2), &data); + if (err != 0) + { + cout << "Failed. Error Code : " << err; + exit(EXIT_FAILURE); + } + + int slen = sizeof(si_other); + char buf[BUFLEN]; + char message[BUFLEN]; + WSADATA wsa; + + //Initialise winsock + printf(" Initialising Winsock...\n"); + if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) + { + printf(" Failed.Error Code : %d", WSAGetLastError()); + Sleep(10000); + exit(EXIT_FAILURE); + } + + printf(" Create Socket \n"); + if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == SOCKET_ERROR) + { + printf(" socket() failed with error code : %d", WSAGetLastError()); + Sleep(10000); + exit(EXIT_FAILURE); + } + + //setup address structure + memset((char*)&si_other, 0, sizeof(si_other)); + si_other.sin_family = AF_INET; + si_other.sin_port = htons(PORT); + InetPton(si_other.sin_family, SERVER.c_str(), &si_other.sin_addr.S_un.S_addr); + //si_other.sin_addr.S_un.S_addr = inet_addr(SERVER.c_str()); + + printf("Will now connect and show streamed data\n"); + // OutputStream Keep alive thread + std::thread keep_alive_thread(keep_alive_timer, KA_DATA_MSG); // change or add threads with more messages + Sleep(1000); + + // InputStream Read udp socket stream + std::thread udp_socket_stream(udp_socket_stream); + std::thread video_stream(VideoStream); + + keep_alive_thread.join(); + udp_socket_stream.join(); + video_stream.join(); + + return 0; +} + +void keep_alive_timer(const string keep_alive_message) { + /*Send Keep Alive messages every second */ + + int slen = sizeof(si_other); + char message[BUFLEN]; + WSADATA wsa; + + std::string data_message = keep_alive_message; + strcpy_s(message, BUFLEN, data_message.c_str()); + + + printf("Start sending keep alive messages \n"); + while (1) + { + printf("Keep Alive Data Sent \n"); + if (sendto(s, message, strlen(message), 0, (struct sockaddr*) & si_other, slen) == SOCKET_ERROR) + { + printf(" sendto() failed with error code : %d", WSAGetLastError()); + Sleep(10000); + exit(EXIT_FAILURE); + } + Sleep(2000); + } + + closesocket(s); + WSACleanup(); +} + +void udp_socket_stream() { + /* + Read and print Stream from udp socket. + */ + + int slen = sizeof(si_other); + char buf[BUFLEN]; + + while (1) + { + //clear the buffer by filling null, it might have previously received data + memset(buf, '\0', BUFLEN); + //try to receive some data, this is a blocking call + if (recvfrom(s, buf, BUFLEN, 0, (struct sockaddr*) & si_other, &slen) == SOCKET_ERROR) + { + printf(" recvfrom() failed with error code : %d", WSAGetLastError()); + Sleep(1000); + exit(EXIT_FAILURE); + } + + puts(buf); + } + + closesocket(s); + WSACleanup(); + +} + +void VideoStream() { + VideoCapture cap("rtsp://" ADDR ":8554/live/scene"); + //VideoCapture cap("rtsp://[" V6_ADDR ":8554]/live/scene"); + if (!cap.isOpened()) { + printf("cannot open camera " ADDR "\n"); + } + //Mat img = Mat(240, 320, CV_8UC3, CV_RGB(128, 0, 0)); + namedWindow("gsttest"); + while (1) { + Mat frame; + cap >> frame; + Mat disp; + resize(frame, disp, Size(), 0.5, 0.5); + imshow("gsttest", disp); + if (waitKey(1) == 'q') break; + } +} + +int main() { + //VideoStream(); + data_stream_main(); + + return 0; +} diff --git a/GSTtest/myOpenCV.h b/GSTtest/myOpenCV.h new file mode 100644 index 0000000..d618da1 --- /dev/null +++ b/GSTtest/myOpenCV.h @@ -0,0 +1,102 @@ + +// OpenCV 3�n, 4�n ���ʃw�b�_�[�t�@�C�� +// T.Nakaguchi, CFME, Chiba Univ., 2019 + +#pragma once + +// �w�b�_�[�t�@�C�� +#pragma warning(disable: 4819) +#include +#pragma warning(default: 4819) + +// �o�[�W�����擾 +#define CV_VERSION_STR CVAUX_STR(CV_MAJOR_VERSION) CVAUX_STR(CV_MINOR_VERSION) CVAUX_STR(CV_SUBMINOR_VERSION) + +// �r���h���[�h +#ifdef _DEBUG +#define CV_EXT_STR "d.lib" +#else +#define CV_EXT_STR ".lib" +#endif + +// ���C�u�����̃����N�i�s�v�ȕ��̓R�����g�A�E�g�j +#define PRE_COMPILE 0 // �C���X�g�[���łȂ� 1 �•ʃ��C�u�����g�p���� 0 +#define PREHEAD "opencv_" + +#if PRE_COMPILE +// OpenCV3 �C���X�g�[���� +#pragma comment(lib, PREHEAD "world" CV_VERSION_STR CV_EXT_STR) // �S�� +#pragma comment(lib, PREHEAD "ts" CV_VERSION_STR CV_EXT_STR) // �f���֘A + +#else +// �•ʂ̃��C�u�����w�� �iCmake��Static�Ŏg�p���Ȃǁj +// ��{���W���[�� +#pragma comment(lib, PREHEAD "core" CV_VERSION_STR CV_EXT_STR) // Core functionality +#pragma comment(lib, PREHEAD "imgproc" CV_VERSION_STR CV_EXT_STR) // Image processing +#pragma comment(lib, PREHEAD "imgcodecs" CV_VERSION_STR CV_EXT_STR) // Image file reading and writing +#pragma comment(lib, PREHEAD "videoio" CV_VERSION_STR CV_EXT_STR) // Video I/O +#pragma comment(lib, PREHEAD "highgui" CV_VERSION_STR CV_EXT_STR) // High-level GUI +//#pragma comment(lib, PREHEAD "video" CV_VERSION_STR CV_EXT_STR) // Video Analysis +//#pragma comment(lib, PREHEAD "calib3d" CV_VERSION_STR CV_EXT_STR) // Camera Calibration and 3D Reconstruction +//#pragma comment(lib, PREHEAD "features2d" CV_VERSION_STR CV_EXT_STR) // 2D Features Framework +//#pragma comment(lib, PREHEAD "objdetect" CV_VERSION_STR CV_EXT_STR) // Object Detection +//#pragma comment(lib, PREHEAD "dnn" CV_VERSION_STR CV_EXT_STR) // Deep Neural Network module +//#pragma comment(lib, PREHEAD "ml" CV_VERSION_STR CV_EXT_STR) // Machine Learning +//#pragma comment(lib, PREHEAD "flann" CV_VERSION_STR CV_EXT_STR) // Clustering and Search in Multi-Dimensional Spaces +//#pragma comment(lib, PREHEAD "photo" CV_VERSION_STR CV_EXT_STR) // Computational Photography +//#pragma comment(lib, PREHEAD "stitching" CV_VERSION_STR CV_EXT_STR) // Images stitching +//#pragma comment(lib, PREHEAD "cudaarithm" CV_VERSION_STR CV_EXT_STR) // CUDA Operations on Matrices +//#pragma comment(lib, PREHEAD "cudabgsegm" CV_VERSION_STR CV_EXT_STR) // CUDA Background Segmentation +//#pragma comment(lib, PREHEAD "cudacodec" CV_VERSION_STR CV_EXT_STR) // CUDA Video Encoding/Decoding +//#pragma comment(lib, PREHEAD "cudafeatures2d" CV_VERSION_STR CV_EXT_STR) // CUDA Feature Detection and Description +//#pragma comment(lib, PREHEAD "cudafilters" CV_VERSION_STR CV_EXT_STR) // CUDA Image Filtering +//#pragma comment(lib, PREHEAD "cudaimgproc" CV_VERSION_STR CV_EXT_STR) // CUDA Image Processing +//#pragma comment(lib, PREHEAD "cudalegacy" CV_VERSION_STR CV_EXT_STR) // CUDA Legacy support +//#pragma comment(lib, PREHEAD "cudaobjdetect" CV_VERSION_STR CV_EXT_STR) // CUDA Object Detection +//#pragma comment(lib, PREHEAD "cudaoptflow" CV_VERSION_STR CV_EXT_STR) // CUDA Optical Flow +//#pragma comment(lib, PREHEAD "cudastereo" CV_VERSION_STR CV_EXT_STR) // CUDA Stereo Correspondence +//#pragma comment(lib, PREHEAD "cudawarping" CV_VERSION_STR CV_EXT_STR) // CUDA Image Warping +//#pragma comment(lib, PREHEAD "cudev" CV_VERSION_STR CV_EXT_STR) // CUDA Device layer +//#pragma comment(lib, PREHEAD "shape" CV_VERSION_STR CV_EXT_STR) // Shape Distance and Matching +//#pragma comment(lib, PREHEAD "superres" CV_VERSION_STR CV_EXT_STR) // Super Resolution +//#pragma comment(lib, PREHEAD "videostab" CV_VERSION_STR CV_EXT_STR) // Video Stabilization +//#pragma comment(lib, PREHEAD "viz" CV_VERSION_STR CV_EXT_STR) // 3D Visualizer + +// �g�����W���[�� +//#pragma comment(lib, PREHEAD "aruco" CV_VERSION_STR CV_EXT_STR) // ArUco Marker Detection +//#pragma comment(lib, PREHEAD "bgsegm" CV_VERSION_STR CV_EXT_STR) // Improved Background-Foreground Segmentation Methods +//#pragma comment(lib, PREHEAD "bioinspired" CV_VERSION_STR CV_EXT_STR) // Biologically inspired vision models and derivated tools +//#pragma comment(lib, PREHEAD "ccalib" CV_VERSION_STR CV_EXT_STR) // Custom Calibration Pattern for 3D reconstruction +//#pragma comment(lib, PREHEAD "cnn_3dobj" CV_VERSION_STR CV_EXT_STR) // 3D object recognition and pose estimation API +//#pragma comment(lib, PREHEAD "cvv" CV_VERSION_STR CV_EXT_STR) // GUI for Interactive Visual Debugging of Computer Vision Programs +//#pragma comment(lib, PREHEAD "datasets" CV_VERSION_STR CV_EXT_STR) // Framework for working with different datasets +//#pragma comment(lib, PREHEAD "dnn_objdetect" CV_VERSION_STR CV_EXT_STR) // DNN used for object detection +//#pragma comment(lib, PREHEAD "dpm" CV_VERSION_STR CV_EXT_STR) // Deformable Part-based Models +//#pragma comment(lib, PREHEAD "face" CV_VERSION_STR CV_EXT_STR) // Face Analysis +//#pragma comment(lib, PREHEAD "freetype" CV_VERSION_STR CV_EXT_STR) // Drawing UTF-8 strings with freetype/harfbuzz +//#pragma comment(lib, PREHEAD "fuzzy" CV_VERSION_STR CV_EXT_STR) // Image processing based on fuzzy mathematics +//#pragma comment(lib, PREHEAD "hdf" CV_VERSION_STR CV_EXT_STR) // Hierarchical Data Format I/O routines +//#pragma comment(lib, PREHEAD "hfs" CV_VERSION_STR CV_EXT_STR) // Hierarchical Feature Selection for Efficient Image Segmentation +//#pragma comment(lib, PREHEAD "img_hash" CV_VERSION_STR CV_EXT_STR) // The module brings implementations of different image hashing algorithms. +//#pragma comment(lib, PREHEAD "line_descriptor" CV_VERSION_STR CV_EXT_STR) // Binary descriptors for lines extracted from an image +//#pragma comment(lib, PREHEAD "matlab" CV_VERSION_STR CV_EXT_STR) // MATLAB Bridge +//#pragma comment(lib, PREHEAD "optflow" CV_VERSION_STR CV_EXT_STR) // Optical Flow Algorithms +//#pragma comment(lib, PREHEAD "ovis" CV_VERSION_STR CV_EXT_STR) // OGRE 3D Visualiser +//#pragma comment(lib, PREHEAD "phase_unwrapping" CV_VERSION_STR CV_EXT_STR) // Phase Unwrapping API +//#pragma comment(lib, PREHEAD "plot" CV_VERSION_STR CV_EXT_STR) // Plot function for Mat data +//#pragma comment(lib, PREHEAD "reg" CV_VERSION_STR CV_EXT_STR) // Image Registration +//#pragma comment(lib, PREHEAD "rgbd" CV_VERSION_STR CV_EXT_STR) // RGB-Depth Processing +//#pragma comment(lib, PREHEAD "saliency" CV_VERSION_STR CV_EXT_STR) // Saliency API +//#pragma comment(lib, PREHEAD "sfm" CV_VERSION_STR CV_EXT_STR) // Structure From Motion +//#pragma comment(lib, PREHEAD "stereo" CV_VERSION_STR CV_EXT_STR) // Stereo Correspondance Algorithms +//#pragma comment(lib, PREHEAD "structured_light" CV_VERSION_STR CV_EXT_STR) // Structured Light API +//#pragma comment(lib, PREHEAD "surface_matching" CV_VERSION_STR CV_EXT_STR) // Surface Matching +//#pragma comment(lib, PREHEAD "text" CV_VERSION_STR CV_EXT_STR) // Scene Text Detection and Recognition +//#pragma comment(lib, PREHEAD "tracking" CV_VERSION_STR CV_EXT_STR) // Tracking API +//#pragma comment(lib, PREHEAD "xfeatures2d" CV_VERSION_STR CV_EXT_STR) // Extra 2D Features Framework +//#pragma comment(lib, PREHEAD "ximgproc" CV_VERSION_STR CV_EXT_STR) // Extended Image Processing +//#pragma comment(lib, PREHEAD "xobjdetect" CV_VERSION_STR CV_EXT_STR) // Extended object detection +//#pragma comment(lib, PREHEAD "xphoto" CV_VERSION_STR CV_EXT_STR) // Additional photo processing algorithms +#endif + +using namespace cv; diff --git a/GSTtest/opencv411.props b/GSTtest/opencv411.props new file mode 100644 index 0000000..45beb6f --- /dev/null +++ b/GSTtest/opencv411.props @@ -0,0 +1,15 @@ + + + + + + D:\SDK\OpenCV4.1.1\include;$(IncludePath) + D:\SDK\OpenCV4.1.1\x64\vc16\lib;$(LibraryPath) + + + D:\SDK\OpenCV4.1.1\include;$(IncludePath) + D:\SDK\OpenCV4.1.1\x86\vc16\lib\lib;$(LibraryPath) + + + + diff --git a/GSTtest/vcpkg.props b/GSTtest/vcpkg.props new file mode 100644 index 0000000..d8a3efa --- /dev/null +++ b/GSTtest/vcpkg.props @@ -0,0 +1,15 @@ + + + + + + D:\SDK\vcpkg\installed\x64-windows\include;$(IncludePath) + D:\SDK\vcpkg\installed\x64-windows\lib;$(LibraryPath) + + + D:\SDK\vcpkg\installed\x86-windows\include;$(IncludePath) + D:\SDK\vcpkg\installed\x86-windows\lib;$(LibraryPath) + + + + diff --git a/PrismSoftware.sln b/PrismSoftware.sln new file mode 100644 index 0000000..5afd5c6 --- /dev/null +++ b/PrismSoftware.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29418.71 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GSTtest", "GSTtest\GSTtest.vcxproj", "{BB038458-DFC5-4ACD-96CB-35512801136D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BB038458-DFC5-4ACD-96CB-35512801136D}.Debug|x64.ActiveCfg = Debug|x64 + {BB038458-DFC5-4ACD-96CB-35512801136D}.Debug|x64.Build.0 = Debug|x64 + {BB038458-DFC5-4ACD-96CB-35512801136D}.Debug|x86.ActiveCfg = Debug|Win32 + {BB038458-DFC5-4ACD-96CB-35512801136D}.Debug|x86.Build.0 = Debug|Win32 + {BB038458-DFC5-4ACD-96CB-35512801136D}.Release|x64.ActiveCfg = Release|x64 + {BB038458-DFC5-4ACD-96CB-35512801136D}.Release|x64.Build.0 = Release|x64 + {BB038458-DFC5-4ACD-96CB-35512801136D}.Release|x86.ActiveCfg = Release|Win32 + {BB038458-DFC5-4ACD-96CB-35512801136D}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FC537DD1-39E6-4347-938F-00585EB74831} + EndGlobalSection +EndGlobal diff --git a/README.md b/README.md new file mode 100644 index 0000000..fe99314 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# GSTtest プロジェクト + +### Tobii Glass Proのテスト +- RTSPによる視界カメラ映像取得とUDPによるLive Data取得 +- 要 OpenCV + GStreamer + + +cpprestsdk