Advertisement
Guest User

Untitled

a guest
Feb 17th, 2021
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. // TestCamera.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include "pch.h"
  5.  
  6.  
  7. #include <crtdbg.h>
  8. #include <iostream>
  9. #include <stdint.h>
  10. #include <stdlib.h>
  11.  
  12. #include "opencv2/highgui/highgui.hpp"
  13. #include "opencv2/imgproc/imgproc.hpp"
  14. #include "opencv2/opencv.hpp"
  15.  
  16. #pragma comment(lib,"comctl32.lib")
  17. #pragma comment(lib,"gdi32.lib")
  18. #pragma comment(lib,"vfw32.lib")
  19.  
  20. typedef unsigned long DWORD;
  21.  
  22. extern "C" {
  23. bool _cdecl img_capture ( int which_camera );
  24. int _cdecl img_init();
  25. bool _cdecl img_led ( int which_camera, int16_t mode );
  26. int _cdecl img_read ( int which_camera, unsigned char* pFrameBuffer, DWORD BytesToRead, DWORD dwMilliseconds );
  27. int _cdecl img_readAsy ( int which_camera, unsigned char* pFrameBuffer, DWORD BytesToRead, DWORD dwMilliseconds );
  28. int _cdecl img_reset ( int which_camera );
  29. bool _cdecl img_set_exp ( int which_camera, int16_t exposure );
  30. bool _cdecl img_set_gain ( int which_camera, int16_t gain );
  31. bool _cdecl img_set_lt ( int which_camera, int16_t a2, int16_t a3 );
  32. bool _cdecl img_set_wh ( int which_camera, int16_t w, int16_t h );
  33. }
  34.  
  35. using namespace cv;
  36. using namespace std;
  37.  
  38. unsigned char buffer[ 1024 * 1024 ];
  39.  
  40. int main()
  41. {
  42. uint32_t timeout = 1000;
  43.  
  44. int g_width = 1024, g_height = 1024;
  45. DWORD bytesToRead = g_width * g_height;
  46.  
  47. memset ( &buffer[0], 0xaa, sizeof ( buffer ) );
  48.  
  49. int ret = img_init();
  50. printf ( "%d = img_init\n", ret );
  51.  
  52. ret = img_set_wh ( 1, g_width, g_height );
  53. printf ( "%d = img_set_wh(1,w,h)\n", ret );
  54.  
  55. ret = img_set_wh ( 5, g_width, g_height );
  56. printf ( "%d = img_set_wh(5,w,h)\n", ret );
  57.  
  58. // img_set_exp ( 1, 25 );
  59. // img_set_exp ( 5, 100 );
  60.  
  61. //img_set_gain ( 1, 8 );
  62. // img_set_lt ( 1, 128, 0 );
  63.  
  64.  
  65. // camera indices are to be 1 and 5(looking up)
  66. ret = img_readAsy ( 5, &buffer[0], bytesToRead, timeout );
  67. printf ( "%d = img_readAsy, %d\n", ret, bytesToRead );
  68.  
  69. Mat cameraFrame ( Size ( g_width, g_height ), CV_8UC1, buffer, g_width );
  70.  
  71. imshow ( "camera", cameraFrame );
  72.  
  73. bool quit = false;
  74.  
  75. while ( quit == false ) {
  76.  
  77. switch ( cv::waitKey ( 0 ) ) {
  78.  
  79. case 'd':
  80. ret = img_readAsy ( 1, &buffer[0], bytesToRead, timeout );
  81. printf ( "%d = img_readAsy, %d\n", ret, bytesToRead );
  82. imshow ( "camera", cameraFrame );
  83. break;
  84.  
  85. case 'u':
  86. ret = img_readAsy ( 5, &buffer[0], bytesToRead, timeout );
  87. printf ( "%d = img_readAsy, %d\n", ret, bytesToRead );
  88. imshow ( "camera", cameraFrame );
  89. break;
  90.  
  91. case '0':
  92. img_led ( 1, 0 );
  93. break;
  94.  
  95. case '1':
  96. img_led ( 1, 1 );
  97. break;
  98.  
  99. case '2':
  100. img_led ( 5, 0 );
  101. break;
  102.  
  103. case '3':
  104. img_led ( 5, 1 );
  105. break;
  106.  
  107. case 'q':
  108. quit = true;
  109. break;
  110. }
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement