VideoCfg_Form.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace VzClientSDKDemo
  11. {
  12. public partial class VideoCfg_Form : Form
  13. {
  14. private int m_hLPRClient = 0;
  15. private int m_board_type = 0;
  16. public VideoCfg_Form()
  17. {
  18. InitializeComponent();
  19. }
  20. public void SetLPRHandle(int hLPRClient)
  21. {
  22. m_hLPRClient = hLPRClient;
  23. }
  24. private void LoadVideoSource( )
  25. {
  26. if(m_board_type == 2)
  27. {
  28. tbar_bright.SetRange(0, 255);
  29. tbar_contrast.SetRange(0, 255);
  30. tbar_saturation.SetRange(0, 255);
  31. tbar_definition.SetRange(0, 255);
  32. int brt = 0, cst = 0, sat = 0, hue = 0;
  33. int ret = VzClientSDK.VzLPRClient_GetVideoPara(m_hLPRClient, ref brt, ref cst, ref sat, ref hue);
  34. if (ret == 0)
  35. {
  36. tbar_bright.Value = brt;
  37. tbar_contrast.Value = cst;
  38. tbar_saturation.Value = sat;
  39. tbar_definition.Value = hue;
  40. lblBright.Text = brt.ToString();
  41. lblContrast.Text = cst.ToString();
  42. lblSaturation.Text = sat.ToString();
  43. lblDefinition.Text = hue.ToString();
  44. }
  45. label14.Visible = false;
  46. cmb_video_standard.Visible = false;
  47. cmb_exposure_time.Items.Clear();
  48. cmb_exposure_time.Items.Add("0~3ms");
  49. cmb_exposure_time.Items.Add("0~2ms");
  50. cmb_exposure_time.Items.Add("0~1ms");
  51. int shutter = 0;
  52. ret = VzClientSDK.VzLPRClient_GetShutter(m_hLPRClient, ref shutter);
  53. if (ret == 0)
  54. {
  55. if (shutter == 96)
  56. {
  57. cmb_exposure_time.SelectedIndex = 0;
  58. }
  59. else if (shutter == 64)
  60. {
  61. cmb_exposure_time.SelectedIndex = 1;
  62. }
  63. else if (shutter == 32)
  64. {
  65. cmb_exposure_time.SelectedIndex = 2;
  66. }
  67. }
  68. int flip = 0;
  69. ret = VzClientSDK.VzLPRClient_GetFlip(m_hLPRClient, ref flip);
  70. if (ret == 0)
  71. {
  72. cmb_img_pos.SelectedIndex = flip;
  73. }
  74. int nMode = 0, nStrength = 0;
  75. int nRet = VzClientSDK.VzLPRClient_GetDenoise(m_hLPRClient, ref nMode, ref nStrength);
  76. if (nMode >= 0 && nStrength >= 0)
  77. {
  78. m_cmbDeNoiseMode.SelectedIndex = nMode;
  79. m_cmbDeNoiseLenth.SelectedIndex = nStrength;
  80. }
  81. }
  82. else
  83. {
  84. int brt = 0, cst = 0, sat = 0, hue = 0;
  85. int ret = VzClientSDK.VzLPRClient_GetVideoPara(m_hLPRClient, ref brt, ref cst, ref sat, ref hue);
  86. if (ret == 0)
  87. {
  88. tbar_bright.Value = brt;
  89. tbar_contrast.Value = cst;
  90. tbar_saturation.Value = sat;
  91. tbar_definition.Value = hue;
  92. lblBright.Text = brt.ToString();
  93. lblContrast.Text = cst.ToString();
  94. lblSaturation.Text = sat.ToString();
  95. lblDefinition.Text = hue.ToString();
  96. }
  97. int frequency = 0;
  98. ret = VzClientSDK.VzLPRClient_GetFrequency(m_hLPRClient, ref frequency);
  99. if (ret == 0)
  100. {
  101. cmb_video_standard.SelectedIndex = frequency;
  102. }
  103. int shutter = 0;
  104. ret = VzClientSDK.VzLPRClient_GetShutter(m_hLPRClient, ref shutter);
  105. if (ret == 0)
  106. {
  107. if (shutter == 2)
  108. {
  109. cmb_exposure_time.SelectedIndex = 0;
  110. }
  111. else if (shutter == 3)
  112. {
  113. cmb_exposure_time.SelectedIndex = 1;
  114. }
  115. else if (shutter == 4)
  116. {
  117. cmb_exposure_time.SelectedIndex = 2;
  118. }
  119. }
  120. int flip = 0;
  121. ret = VzClientSDK.VzLPRClient_GetFlip(m_hLPRClient, ref flip);
  122. if (ret == 0)
  123. {
  124. cmb_img_pos.SelectedIndex = flip;
  125. }
  126. }
  127. }
  128. private void LoadVideoCfg()
  129. {
  130. string strRateval = "512";
  131. if (m_hLPRClient > 0)
  132. {
  133. int nSizeVal = 0, nRateval = 0, nEncodeType = 0, modeval = 0, bitval = 0, ratelist = 0, levelval = 0;
  134. int ret = -1;
  135. if (m_board_type == 2)
  136. {
  137. cmb_frame_size.Items.Clear();
  138. cmb_frame_size.Items.Add("640x360");
  139. cmb_frame_size.Items.Add("720x576");
  140. cmb_frame_size.Items.Add("1280x720");
  141. cmb_frame_size.Items.Add("1920x1080");
  142. ret = VzClientSDK.VzLPRClient_GetVideoFrameSizeIndexEx(m_hLPRClient, ref nSizeVal);
  143. if (nSizeVal == 41943400)
  144. {
  145. cmb_frame_size.SelectedIndex = 0;
  146. }
  147. else if (nSizeVal == 47186496)
  148. {
  149. cmb_frame_size.SelectedIndex = 1;
  150. }
  151. else if (nSizeVal == 83886800)
  152. {
  153. cmb_frame_size.SelectedIndex = 2;
  154. }
  155. else if (nSizeVal == 125830200)
  156. {
  157. cmb_frame_size.SelectedIndex = 3;
  158. }
  159. else
  160. {
  161. cmb_frame_size.SelectedIndex = 0;
  162. }
  163. cmb_encode_type.SelectedIndex = 0;
  164. cmb_encode_type.Items.RemoveAt(1);
  165. }
  166. else
  167. {
  168. ret = VzClientSDK.VzLPRClient_GetVideoEncodeType(m_hLPRClient, ref nEncodeType);
  169. if (ret == 0)
  170. {
  171. if (nEncodeType == 0)
  172. {
  173. cmb_encode_type.SelectedIndex = 0;
  174. cmb_compress_mode.Enabled = true;
  175. }
  176. else
  177. {
  178. cmb_encode_type.SelectedIndex = 1;
  179. cmb_compress_mode.Enabled = false;
  180. }
  181. }
  182. ret = VzClientSDK.VzLPRClient_GetVideoFrameSizeIndex(m_hLPRClient, ref nSizeVal);
  183. if (ret == 0)
  184. {
  185. if (nSizeVal == 0)
  186. {
  187. cmb_frame_size.SelectedIndex = 1;
  188. }
  189. else if (nSizeVal == 1)
  190. {
  191. cmb_frame_size.SelectedIndex = 0;
  192. }
  193. else
  194. {
  195. cmb_frame_size.SelectedIndex = nSizeVal;
  196. }
  197. }
  198. }
  199. ret = VzClientSDK.VzLPRClient_GetVideoFrameRate(m_hLPRClient, ref nRateval);
  200. if (ret == 0 && nRateval > 0)
  201. {
  202. cmb_frame_rate.SelectedIndex = nRateval - 1;
  203. }
  204. ret = VzClientSDK.VzLPRClient_GetVideoCompressMode(m_hLPRClient, ref modeval);
  205. if (ret == 0)
  206. {
  207. cmb_compress_mode.SelectedIndex = modeval;
  208. if (modeval == 0)
  209. {
  210. txt_rateval.Enabled = true;
  211. }
  212. else
  213. {
  214. txt_rateval.Enabled = false;
  215. }
  216. }
  217. ret = VzClientSDK.VzLPRClient_GetVideoCBR(m_hLPRClient, ref bitval, ref ratelist);
  218. if (ret == 0)
  219. {
  220. strRateval = bitval.ToString();
  221. }
  222. ret = VzClientSDK.VzLPRClient_GetVideoVBR(m_hLPRClient, ref levelval);
  223. if (ret == 0)
  224. {
  225. cmb_img_quality.SelectedIndex = levelval;
  226. }
  227. }
  228. txt_rateval.Text = strRateval;
  229. }
  230. private void btnSave_Click(object sender, EventArgs e)
  231. {
  232. string sRateVal = txt_rateval.Text.ToString();
  233. int nRate = Int32.Parse(sRateVal);
  234. int ret = -1;
  235. int nSizeVal = cmb_frame_size.SelectedIndex;
  236. if (m_board_type == 2)
  237. {
  238. if (nRate < 512 || nRate > 5000)
  239. {
  240. MessageBox.Show("码流范围为512-5000,请重新输入!");
  241. return;
  242. }
  243. switch (nSizeVal)
  244. {
  245. case 0:
  246. nSizeVal = 41943400; break;
  247. case 1:
  248. nSizeVal = 47186496; break;
  249. case 2:
  250. nSizeVal = 83886800; break;
  251. case 3:
  252. nSizeVal = 125830200; break;
  253. default:
  254. break;
  255. }
  256. ret = VzClientSDK.VzLPRClient_SetVideoFrameSizeIndexEx(m_hLPRClient, nSizeVal);
  257. if (ret != 0)
  258. {
  259. MessageBox.Show("设置分辨率失败,请重试!");
  260. return;
  261. }
  262. }
  263. else
  264. {
  265. if (nRate <= 99 || nRate > 5000)
  266. {
  267. MessageBox.Show("码流范围为100-5000,请重新输入!");
  268. return;
  269. }
  270. if (nSizeVal == 0)
  271. {
  272. nSizeVal = 1;
  273. }
  274. else if (nSizeVal == 1)
  275. {
  276. nSizeVal = 0;
  277. }
  278. ret = VzClientSDK.VzLPRClient_SetVideoFrameSizeIndex(m_hLPRClient, nSizeVal);
  279. if (ret != 0)
  280. {
  281. MessageBox.Show("设置分辨率失败,请重试!");
  282. return;
  283. }
  284. }
  285. int nRateval = cmb_frame_rate.SelectedIndex + 1;
  286. ret = VzClientSDK.VzLPRClient_SetVideoFrameRate(m_hLPRClient, nRateval);
  287. if (ret != 0)
  288. {
  289. MessageBox.Show("设置帧率失败,请重试!");
  290. return;
  291. }
  292. int nEncodeType = (cmb_encode_type.SelectedIndex == 0) ? 0 : 2;
  293. ret = VzClientSDK.VzLPRClient_SetVideoEncodeType(m_hLPRClient, nEncodeType);
  294. if (ret != 0)
  295. {
  296. MessageBox.Show("设置编码方式失败,请重试!");
  297. return;
  298. }
  299. if (cmb_compress_mode.Enabled)
  300. {
  301. int modeval = cmb_compress_mode.SelectedIndex;
  302. ret = VzClientSDK.VzLPRClient_SetVideoCompressMode(m_hLPRClient, modeval);
  303. if (ret != 0)
  304. {
  305. MessageBox.Show("设置码流控制失败,请重试!");
  306. return;
  307. }
  308. }
  309. int level = cmb_img_quality.SelectedIndex;
  310. ret = VzClientSDK.VzLPRClient_SetVideoVBR(m_hLPRClient, level);
  311. if (ret != 0)
  312. {
  313. MessageBox.Show("设置图像质量失败,请重试!");
  314. return;
  315. }
  316. if (txt_rateval.Enabled)
  317. {
  318. ret = VzClientSDK.VzLPRClient_SetVideoCBR(m_hLPRClient, nRate);
  319. if (ret != 0)
  320. {
  321. MessageBox.Show("设置码流上限失败,请重试!");
  322. return;
  323. }
  324. }
  325. MessageBox.Show("设置成功!");
  326. }
  327. private async void VideoCfg_Form_Load(object sender, EventArgs e)
  328. {
  329. VzClientSDK.VzLPRClient_GetHwBoardType(m_hLPRClient, ref m_board_type);
  330. // await Task.Factory.StartNew(async() => { await load01(); });
  331. LoadVideoCfg();
  332. Application.DoEvents();
  333. LoadVideoSource();
  334. Application.DoEvents();
  335. }
  336. private Task load01()
  337. {
  338. return Task.Factory.StartNew(()=> { });
  339. }
  340. private void cmb_encode_type_SelectedIndexChanged(object sender, EventArgs e)
  341. {
  342. int nCurSel = cmb_encode_type.SelectedIndex;
  343. if (nCurSel == 0)
  344. {
  345. cmb_compress_mode.Enabled = true;
  346. }
  347. else
  348. {
  349. cmb_compress_mode.Enabled = false;
  350. }
  351. }
  352. private void cmb_compress_mode_SelectedIndexChanged(object sender, EventArgs e)
  353. {
  354. if (cmb_compress_mode.Enabled)
  355. {
  356. int nCurSel = cmb_compress_mode.SelectedIndex;
  357. if (nCurSel == 0)
  358. {
  359. txt_rateval.Enabled = true;
  360. }
  361. else
  362. {
  363. txt_rateval.Enabled = false;
  364. }
  365. }
  366. else
  367. {
  368. txt_rateval.Enabled = false;
  369. }
  370. }
  371. private void btnRecovery_Click(object sender, EventArgs e)
  372. {
  373. if (m_board_type == 2)
  374. {
  375. int brt = 128;
  376. tbar_bright.Value = brt;
  377. int cst = 138;
  378. tbar_contrast.Value = cst;
  379. int sat = 128;
  380. tbar_saturation.Value = sat;
  381. int hue = 140;
  382. tbar_definition.Value = hue;
  383. VzClientSDK.VzLPRClient_SetVideoPara(m_hLPRClient, brt, cst, sat, hue);
  384. VzClientSDK.VzLPRClient_SetShutter(m_hLPRClient, 96);
  385. cmb_exposure_time.SelectedIndex = 0;
  386. VzClientSDK.VzLPRClient_SetFlip(m_hLPRClient, 0);
  387. cmb_img_pos.SelectedIndex = 0;
  388. VzClientSDK.VzLPRClient_SetDenoise(m_hLPRClient, 3, 2);
  389. m_cmbDeNoiseMode.SelectedIndex = 3;
  390. m_cmbDeNoiseLenth.SelectedIndex = 2;
  391. lblBright.Text = brt.ToString();
  392. lblContrast.Text = cst.ToString();
  393. lblSaturation.Text = sat.ToString();
  394. lblDefinition.Text = hue.ToString();
  395. }
  396. else
  397. {
  398. int brt = 50;
  399. tbar_bright.Value = brt;
  400. int cst = 40;
  401. tbar_contrast.Value = cst;
  402. int sat = 30;
  403. tbar_saturation.Value = sat;
  404. int hue = 50;
  405. tbar_definition.Value = hue;
  406. VzClientSDK.VzLPRClient_SetVideoPara(m_hLPRClient, brt, cst, sat, hue);
  407. VzClientSDK.VzLPRClient_SetFrequency(m_hLPRClient, 1);
  408. cmb_video_standard.SelectedIndex = 1;
  409. VzClientSDK.VzLPRClient_SetShutter(m_hLPRClient, 3);
  410. cmb_exposure_time.SelectedIndex = 1;
  411. VzClientSDK.VzLPRClient_SetFlip(m_hLPRClient, 0);
  412. cmb_img_pos.SelectedIndex = 0;
  413. lblBright.Text = brt.ToString();
  414. lblContrast.Text = cst.ToString();
  415. lblSaturation.Text = sat.ToString();
  416. lblDefinition.Text = hue.ToString();
  417. }
  418. }
  419. private void tbar_bright_MouseUp(object sender, MouseEventArgs e)
  420. {
  421. int brt = tbar_bright.Value;
  422. int cst = tbar_contrast.Value;
  423. int sat = tbar_saturation.Value;
  424. int hue = tbar_definition.Value;
  425. lblBright.Text = brt.ToString();
  426. lblContrast.Text = cst.ToString();
  427. lblSaturation.Text = sat.ToString();
  428. lblDefinition.Text = hue.ToString();
  429. VzClientSDK.VzLPRClient_SetVideoPara(m_hLPRClient, brt, cst, sat, hue);
  430. }
  431. private void tbar_contrast_MouseUp(object sender, MouseEventArgs e)
  432. {
  433. int brt = tbar_bright.Value;
  434. int cst = tbar_contrast.Value;
  435. int sat = tbar_saturation.Value;
  436. int hue = tbar_definition.Value;
  437. lblBright.Text = brt.ToString();
  438. lblContrast.Text = cst.ToString();
  439. lblSaturation.Text = sat.ToString();
  440. lblDefinition.Text = hue.ToString();
  441. VzClientSDK.VzLPRClient_SetVideoPara(m_hLPRClient, brt, cst, sat, hue);
  442. }
  443. private void tbar_saturation_MouseUp(object sender, MouseEventArgs e)
  444. {
  445. int brt = tbar_bright.Value;
  446. int cst = tbar_contrast.Value;
  447. int sat = tbar_saturation.Value;
  448. int hue = tbar_definition.Value;
  449. lblBright.Text = brt.ToString();
  450. lblContrast.Text = cst.ToString();
  451. lblSaturation.Text = sat.ToString();
  452. lblDefinition.Text = hue.ToString();
  453. VzClientSDK.VzLPRClient_SetVideoPara(m_hLPRClient, brt, cst, sat, hue);
  454. }
  455. private void tbar_definition_MouseUp(object sender, MouseEventArgs e)
  456. {
  457. int brt = tbar_bright.Value;
  458. int cst = tbar_contrast.Value;
  459. int sat = tbar_saturation.Value;
  460. int hue = tbar_definition.Value;
  461. lblBright.Text = brt.ToString();
  462. lblContrast.Text = cst.ToString();
  463. lblSaturation.Text = sat.ToString();
  464. lblDefinition.Text = hue.ToString();
  465. VzClientSDK.VzLPRClient_SetVideoPara(m_hLPRClient, brt, cst, sat, hue);
  466. }
  467. private void cmb_video_standard_SelectedIndexChanged(object sender, EventArgs e)
  468. {
  469. int frequency = cmb_video_standard.SelectedIndex;
  470. int ret = VzClientSDK.VzLPRClient_SetFrequency(m_hLPRClient, frequency);
  471. }
  472. private void cmb_exposure_time_SelectedIndexChanged(object sender, EventArgs e)
  473. {
  474. if (m_board_type == 2)
  475. {
  476. int shutter = 0;
  477. int curSel = cmb_exposure_time.SelectedIndex;
  478. if (curSel == 0)
  479. {
  480. shutter = 96;
  481. }
  482. else if (curSel == 1)
  483. {
  484. shutter = 64;
  485. }
  486. else if (curSel == 2)
  487. {
  488. shutter = 32;
  489. }
  490. int ret = VzClientSDK.VzLPRClient_SetShutter(m_hLPRClient, shutter);
  491. }
  492. else
  493. {
  494. int shutter = 0;
  495. int curSel = cmb_exposure_time.SelectedIndex;
  496. if (curSel == 0)
  497. {
  498. shutter = 2;
  499. }
  500. else if (curSel == 1)
  501. {
  502. shutter = 3;
  503. }
  504. else if (curSel == 2)
  505. {
  506. shutter = 4;
  507. }
  508. int ret = VzClientSDK.VzLPRClient_SetShutter(m_hLPRClient, shutter);
  509. }
  510. }
  511. private void cmb_img_pos_SelectedIndexChanged(object sender, EventArgs e)
  512. {
  513. int flip = cmb_img_pos.SelectedIndex;
  514. int ret = VzClientSDK.VzLPRClient_SetFlip(m_hLPRClient, flip);
  515. }
  516. private void m_cmbDeNoiseMode_SelectedIndexChanged(object sender, EventArgs e)
  517. {
  518. int mode = m_cmbDeNoiseMode.SelectedIndex;
  519. int strength = m_cmbDeNoiseLenth.SelectedIndex;
  520. int ret = VzClientSDK.VzLPRClient_SetDenoise(m_hLPRClient, mode, strength);
  521. }
  522. private void m_cmbDeNoiseLenth_SelectedIndexChanged(object sender, EventArgs e)
  523. {
  524. int mode = m_cmbDeNoiseMode.SelectedIndex;
  525. int strength = m_cmbDeNoiseLenth.SelectedIndex;
  526. int ret = VzClientSDK.VzLPRClient_SetDenoise(m_hLPRClient, mode, strength);
  527. }
  528. }
  529. }