OcrRule.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. import QtQuick
  2. import QtQuick.Controls
  3. import FluentUI
  4. import "../Component"
  5. Item {
  6. MirrorImage{
  7. id: mirrorImage
  8. anchors{
  9. left: parent.left
  10. top: parent.top
  11. }
  12. width: 1280
  13. height: 720 + 50
  14. imageWidth: 1280
  15. imageHeight: 720
  16. onRoi_red_changed: function(roi){
  17. if(typeof ruleFile.currentItem === "undefined"){
  18. return
  19. }
  20. ruleFile.currentItem.roiFront = roi
  21. }
  22. onRoi_green_changed: function(roi){
  23. if(typeof ruleFile.currentItem === "undefined"){
  24. return
  25. }
  26. ruleFile.currentItem.roiBack = roi
  27. }
  28. }
  29. RuleFile{
  30. id: ruleFile
  31. anchors{
  32. left: mirrorImage.right
  33. leftMargin: 10
  34. right: parent.right
  35. top: parent.top
  36. }
  37. height: 600
  38. addFunc: add
  39. editFunc: edit
  40. saveFunc: save
  41. onCurrentItemChanged: {
  42. if(currentItem === "" || typeof currentItem === "undefined"){
  43. return
  44. }
  45. var [x, y, width, height] = currentItem.roiFront.split(',')
  46. mirrorImage.roiRed_x = parseInt(x)
  47. mirrorImage.roiRed_y = parseInt(y)
  48. mirrorImage.roiRed_width = parseInt(width)
  49. mirrorImage.roiRed_height = parseInt(height)
  50. var [x, y, width, height] = currentItem.roiBack.split(',')
  51. mirrorImage.roiGreen_x = parseInt(x)
  52. mirrorImage.roiGreen_y = parseInt(y)
  53. mirrorImage.roiGreen_width = parseInt(width)
  54. mirrorImage.roiGreen_height = parseInt(height)
  55. }
  56. }
  57. FluArea {
  58. id: ruleArea
  59. anchors{
  60. left: mirrorImage.right
  61. leftMargin: 10
  62. right: parent.right
  63. top: ruleFile.bottom
  64. topMargin: 12
  65. bottom: parent.bottom
  66. }
  67. Column{
  68. id: coi
  69. anchors{
  70. top: parent.top
  71. bottom: parent.bottom
  72. left: parent.left
  73. leftMargin: 20
  74. right: parent.right
  75. rightMargin: 20
  76. }
  77. spacing: 5
  78. //头
  79. Item{
  80. width: coi.width
  81. height: 40
  82. FluText{
  83. anchors.left: parent.left
  84. anchors.verticalCenter: parent.verticalCenter
  85. text: "Editing rule"
  86. font: FluTextStyle.Subtitle
  87. }
  88. }
  89. //item name 这个参数项的名称
  90. Item{
  91. width: coi.width
  92. height: 40
  93. FluText{
  94. anchors.left: parent.left
  95. anchors.verticalCenter: parent.verticalCenter
  96. text: "Item name"
  97. font: FluTextStyle.BodyStrong
  98. }
  99. FluTextBox{
  100. id: itemName
  101. anchors{
  102. right: parent.right
  103. verticalCenter: parent.verticalCenter
  104. }
  105. placeholderText:"单行输入框"
  106. disabled: true
  107. text: (typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.itemName
  108. width: 200
  109. }
  110. }
  111. // roi front
  112. Item{
  113. width: coi.width
  114. height: 40
  115. FluText{
  116. anchors.left: parent.left
  117. anchors.verticalCenter: parent.verticalCenter
  118. text: "Roi front"
  119. font: FluTextStyle.BodyStrong
  120. }
  121. FluTextBox{
  122. id: roiFront
  123. anchors{
  124. right: parent.right
  125. verticalCenter: parent.verticalCenter
  126. }
  127. disabled: true
  128. text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.roiFront
  129. placeholderText:"0,0,100,100"
  130. width: 200
  131. }
  132. }
  133. //roi back
  134. Item{
  135. width: coi.width
  136. height: 40
  137. FluText{
  138. anchors.left: parent.left
  139. anchors.verticalCenter: parent.verticalCenter
  140. text: "Roi Back"
  141. font: FluTextStyle.BodyStrong
  142. }
  143. FluTextBox{
  144. id: roiBack
  145. anchors{
  146. right: parent.right
  147. verticalCenter: parent.verticalCenter
  148. }
  149. disabled: true
  150. text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.roiBack
  151. placeholderText:"0,0,100,100"
  152. width: 200
  153. }
  154. }
  155. //ocr 模式
  156. Item{
  157. width: coi.width
  158. height: 40
  159. FluText{
  160. anchors.left: parent.left
  161. anchors.verticalCenter: parent.verticalCenter
  162. text: "Mode"
  163. font: FluTextStyle.BodyStrong
  164. }
  165. FComboBox{
  166. id: mode
  167. anchors{
  168. right: parent.right
  169. verticalCenter: parent.verticalCenter
  170. }
  171. width: 200
  172. model: ["Single", "Full", "Digit", "DigitCounter", "Duration"]
  173. currentIndex: if(typeof ruleFile.currentItem !== "undefined"){
  174. if(ruleFile.currentItem.mode === "Single"){
  175. return 0
  176. }else if(ruleFile.currentItem.mode === "Full"){
  177. return 1
  178. }else if(ruleFile.currentItem.mode === "Digit"){
  179. return 2
  180. }else if(ruleFile.currentItem.mode === "DigitCounter"){
  181. return 3
  182. }else if(ruleFile.currentItem.mode === "Duration"){
  183. return 4
  184. }
  185. }else{return 0}
  186. onActivated: {
  187. if(currentIndex === 0){
  188. ruleFile.currentItem.mode = "Single"
  189. }
  190. else if(currentIndex === 1){
  191. ruleFile.currentItem.mode = "Full"
  192. }
  193. else if(currentIndex === 2){
  194. ruleFile.currentItem.mode = "Digit"
  195. }
  196. else if(currentIndex === 3){
  197. ruleFile.currentItem.mode = "DigitCounter"
  198. }
  199. else if(currentIndex === 4){
  200. ruleFile.currentItem.mode = "Duration"
  201. }
  202. }
  203. }
  204. }
  205. // ocr 方法
  206. Item{
  207. width: coi.width
  208. height: 40
  209. FluText{
  210. anchors.left: parent.left
  211. anchors.verticalCenter: parent.verticalCenter
  212. text: "Method"
  213. font: FluTextStyle.BodyStrong
  214. }
  215. FComboBox{
  216. id: method
  217. anchors{
  218. right: parent.right
  219. verticalCenter: parent.verticalCenter
  220. }
  221. width: 200
  222. currentIndex: 0
  223. model: ["Default"]
  224. onActivated: {
  225. }
  226. }
  227. }
  228. //keyword 匹配字段
  229. Item{
  230. width: coi.width
  231. height: 40
  232. FluText{
  233. anchors.left: parent.left
  234. anchors.verticalCenter: parent.verticalCenter
  235. text: "Keyword"
  236. font: FluTextStyle.BodyStrong
  237. }
  238. FluTextBox{
  239. id: keyword
  240. anchors{
  241. right: parent.right
  242. verticalCenter: parent.verticalCenter
  243. }
  244. width: 200
  245. text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.keyword
  246. placeholderText:""
  247. onEditingFinished: {
  248. if(typeof ruleFile.currentItem === "undefined"){
  249. return
  250. }
  251. ruleFile.currentItem.keyword = text
  252. }
  253. }
  254. }
  255. //描述 description
  256. Item{
  257. width: coi.width
  258. height: 40
  259. FluText{
  260. anchors.left: parent.left
  261. anchors.verticalCenter: parent.verticalCenter
  262. text: "Description"
  263. font: FluTextStyle.BodyStrong
  264. }
  265. FluTextBox{
  266. id: description
  267. anchors{
  268. right: parent.right
  269. verticalCenter: parent.verticalCenter
  270. }
  271. width: 200
  272. text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.description
  273. placeholderText:"input your description"
  274. onEditingFinished: {
  275. if(typeof ruleFile.currentItem === "undefined"){
  276. return
  277. }
  278. ruleFile.currentItem.description = text
  279. }
  280. }
  281. }
  282. }
  283. }
  284. // 帮助
  285. FluArea{
  286. id: ruleHelp
  287. anchors{
  288. left: parent.left
  289. right: ruleArea.left
  290. rightMargin: 10
  291. top: mirrorImage.bottom
  292. topMargin: 10
  293. bottom: parent.bottom
  294. }
  295. FluText{
  296. leftPadding: 12
  297. topPadding: 12
  298. text: "红色的框(Roi front = roi)表示这一个项OCR识别的默认范围,绿色的框(Roi Back = area)表示如果识别到会点击的的范围。
  299. 在移动边框时右边的roi并不会实时显示,当切换软件的焦点时更新显示,但是具体的数值是更新的。
  300. 投屏的设置最上边点击即可"
  301. }
  302. }
  303. function add(){
  304. const item ={}
  305. item["itemName"] = "new"
  306. item["roiFront"] = "0,0,100,100"
  307. item["roiBack"] = "0,0,100,100"
  308. item["mode"] = "Single"
  309. item["method"] = "Default"
  310. item["keyword"] = ""
  311. item["description"] = "Ocr-description"
  312. showSuccess("Add new item")
  313. return item
  314. }
  315. function edit(model){
  316. }
  317. function save(){
  318. const data = []
  319. for(var i=0; i<ruleFile.list_model.count; i++){
  320. const item = ruleFile.list_model.get(i)
  321. const itemData = {}
  322. itemData["itemName"] = item["itemName"]
  323. itemData["roiFront"] = item["roiFront"]
  324. itemData["roiBack"] = item["roiBack"]
  325. itemData["mode"] = item["mode"]
  326. itemData["method"] = item["method"]
  327. itemData["keyword"] = item["keyword"]
  328. itemData["description"] = item["description"]
  329. data.push(itemData)
  330. }
  331. ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data, null, " "))
  332. showSuccess("Save file")
  333. }
  334. }