风过无痕 发表于 2023-9-13 14:48:46

【已解决】查找指定字符串,获取指定字符串所在行后面的内容

本帖最后由 风过无痕 于 2023-9-13 19:21 编辑

使用OcrLiteOnnx识别后输出一个txt文件,通过查找指定字符串(FullDetectTime),获取指定字符串所在行后面的内容,
3333.png-result.txt 内容如下。
=====Input Params=====
numThread(4),padding(50),maxSideLen(1024),boxScoreThresh(0.600000),boxThresh(0.300000),unClipRatio(2.000000),doAngle(1),mostAngle(1)
=====Init Models=====
--- Init DbNet ---
--- Init AngleNet ---
--- Init CrnnNet ---
Init Models Success!
=====Start detect=====
ScaleParam(sw:876,sh:565,dw:864,dh:544,0.986301,0.962832)
---------- step: dbNet getTextBoxes ----------
dbNetTime(192.295100ms)
TextBox(+padding), , , ]
TextBox(+padding), , , ]
TextBox(+padding), , , ]
TextBox(+padding), , , ]
TextBox(+padding), , , ]
TextBox(+padding), , , ]
TextBox(+padding), , , ]
TextBox(+padding), , , ]
TextBox(+padding), , , ]
TextBox(+padding), , , ]
TextBox(+padding), , , ]
TextBox(+padding), , , ]
TextBox(+padding), , , ]
TextBox(+padding), , , ]
TextBox(+padding), , , ]
TextBox(+padding), , , ]
---------- step: drawTextBoxes ----------
---------- step: angleNet getAngles ----------
angle
angle
angle
angle
angle
angle
angle
angle
angle
angle
angle
angle
angle
angle
angle
angle
---------- step: crnnNet getTextLine ----------
textLine(Reguired Parameters)
textScores{0.999981 ,0.999996 ,0.58634 ,0.999715 ,0.995936 ,0.999955 ,0.999983 ,0.999992 ,0.886223 ,0.999695 ,0.999974 ,0.765284 ,0.99996 ,0.998921 ,0.99999 ,0.999992 ,0.999995 ,0.999998 ,0.999908}
crnnTime(20.662500ms)
textLine(-d --models: models directory)
textScores{0.971931 ,0.999992 ,0.763933 ,0.999226 ,0.99833 ,0.998141 ,0.999823 ,0.99999 ,0.999995 ,0.937489 ,0.999978 ,0.998909 ,0.799055 ,0.999976 ,0.999929 ,0.999994 ,1 ,0.958652 ,0.999976 ,0.972045 ,0.99995 ,0.99992 ,0.999459 ,0.999999 ,0.999845 ,0.999947 ,0.999704 ,0.959895 ,0.999918}
crnnTime(19.034700ms)
textLine(1--det: modelfile name of det)
textScores{0.993581 ,0.998598 ,0.996938 ,0.999982 ,0.999999 ,0.999928 ,0.989098 ,0.537973 ,0.999939 ,0.999687 ,0.999978 ,0.999998 ,0.990987 ,0.999863 ,0.999651 ,0.999362 ,0.999989 ,0.918678 ,0.999916 ,0.999997 ,0.999902 ,0.999998 ,0.994534 ,0.999896 ,0.999962 ,0.961395 ,0.999849 ,0.999999 ,0.999716}
crnnTime(17.594200ms)
textLine(-2--cls: model file name ofcls.)
textScores{0.871999 ,0.99635 ,0.996149 ,0.995044 ,0.998945 ,0.947315 ,0.999982 ,0.99903 ,0.503604 ,0.9971 ,0.986798 ,0.999994 ,0.999998 ,0.992267 ,0.8509 ,0.99985 ,0.899121 ,0.997184 ,0.999996 ,0.829029 ,0.999823 ,0.999147 ,0.999897 ,0.999999 ,0.947834 ,0.999566 ,0.996196 ,0.99896 ,0.932875 ,0.999947 ,0.994501}
crnnTime(15.912100ms)
textLine(3 --rec: model file name of rec)
textScores{0.999448 ,0.745592 ,0.995979 ,0.99942 ,0.999931 ,0.999982 ,0.999812 ,0.999195 ,0.889151 ,0.999376 ,0.999888 ,0.999994 ,0.999992 ,0.891905 ,0.537517 ,0.999889 ,0.999756 ,0.999106 ,0.999983 ,0.783524 ,0.99917 ,0.999204 ,0.99931 ,0.999995 ,0.98394 ,0.999905 ,0.999894 ,0.654936 ,0.999569 ,0.999971 ,0.998999}
crnnTime(17.106300ms)
textLine(-4 --keys: keys file name)
textScores{0.994039 ,0.999897 ,0.873459 ,0.995252 ,0.999093 ,0.92198 ,0.999996 ,0.999995 ,0.999978 ,0.996877 ,0.999049 ,0.95359 ,0.999997 ,0.999998 ,0.99994 ,0.999089 ,0.999859 ,0.997085 ,0.922239 ,0.999993 ,0.993726 ,0.989337 ,0.999161 ,0.974112 ,0.999997}
crnnTime(9.012800ms)
textLine(-i --image: path of target image)
textScores{0.991694 ,0.981201 ,0.838374 ,0.995901 ,0.997532 ,0.99966 ,0.998227 ,0.979481 ,0.999826 ,0.999988 ,0.997878 ,0.998788 ,0.999927 ,0.998984 ,0.724098 ,0.999421 ,0.998763 ,0.999174 ,0.999956 ,0.980585 ,0.999993 ,0.998467 ,0.999089 ,0.999989 ,0.999985 ,0.99999 ,0.586902 ,0.996801 ,0.998718 ,0.993326 ,0.999964 ,0.999829}
crnnTime(14.255900ms)
textLine(Optional Parameters)
textScores{0.993038 ,0.998139 ,0.999921 ,0.754217 ,0.999891 ,0.997353 ,0.988037 ,0.891861 ,0.933035 ,0.99999 ,0.999985 ,0.999992 ,0.999477 ,0.998564 ,0.999998 ,0.999992 ,0.999997 ,0.999997 ,0.999947}
crnnTime(11.552500ms)
textLine(t--numThread: value of numThread(int), default: 4)
textScores{0.999885 ,0.975239 ,0.990108 ,0.999618 ,0.999923 ,0.999768 ,0.999989 ,0.999952 ,0.999964 ,0.999964 ,0.99998 ,0.999959 ,0.999686 ,0.556465 ,0.997043 ,0.999831 ,0.999009 ,0.99981 ,0.999977 ,0.994305 ,0.999788 ,0.999815 ,0.943894 ,0.999457 ,0.999989 ,0.999738 ,0.999974 ,0.99998 ,0.99977 ,0.999932 ,0.999955 ,0.99994 ,0.999606 ,0.999892 ,0.76333 ,0.999525 ,0.999395 ,0.997326 ,0.776834 ,0.998433 ,0.999997 ,0.999883 ,0.998526 ,0.999932 ,0.996105 ,0.999929 ,0.999078 ,0.662191 ,0.999999}
crnnTime(23.145000ms)
textLine(-P --Padding: value of padding(int, defsult: 50)
textScores{0.609485 ,0.848432 ,0.64579 ,0.993584 ,0.995777 ,0.779211 ,0.993535 ,0.999986 ,0.998245 ,1 ,0.999949 ,1 ,0.99018 ,0.551765 ,0.998744 ,0.99679 ,0.999887 ,0.984021 ,0.995999 ,0.995717 ,0.996162 ,0.999949 ,0.881758 ,0.99999 ,0.995009 ,0.999965 ,0.986532 ,0.989835 ,0.999741 ,0.999973 ,0.994037 ,0.998453 ,0.999986 ,0.996908 ,0.999945 ,0.983816 ,0.998651 ,0.999973 ,0.976265 ,0.777535 ,0.999739 ,0.758488 ,0.740949 ,0.992357 ,0.902409 ,0.999841 ,0.980814}
crnnTime(15.191600ms)
textLine(-s --maxSideLen: Long side of picture for resize(int), default: 1024)
textScores{0.782858 ,0.99673 ,0.586052 ,0.993805 ,0.998007 ,0.999572 ,0.998169 ,0.999376 ,0.999277 ,0.999986 ,0.999993 ,0.999995 ,0.997178 ,0.999982 ,0.999771 ,0.998631 ,0.916409 ,0.99977 ,0.999698 ,0.999965 ,0.997191 ,0.998397 ,0.99997 ,0.999969 ,0.999997 ,0.999999 ,0.701232 ,0.999701 ,0.999919 ,0.998795 ,0.999805 ,0.999986 ,0.999947 ,0.99982 ,0.997522 ,0.999819 ,0.999999 ,0.980771 ,0.999925 ,0.999946 ,0.999993 ,0.995677 ,0.999965 ,0.999999 ,0.999991 ,0.937972 ,0.999995 ,0.999992 ,0.909894 ,0.997478 ,0.999432 ,0.999953 ,0.999942 ,0.999531 ,0.906826 ,0.99988 ,0.999999 ,0.999926 ,0.997109 ,0.999082 ,0.991298 ,0.99998 ,0.99975 ,0.881417 ,0.999891 ,0.998966 ,0.999872 ,0.999905}
crnnTime(25.538500ms)
textLine(-b --boxScoreThresh: value of boxScoreThresh(float), default: 0.6)
textScores{0.97664 ,0.998585 ,0.926882 ,0.997849 ,0.997359 ,0.999221 ,0.99728 ,0.995407 ,0.999173 ,0.999506 ,0.999826 ,0.995116 ,0.99991 ,0.999888 ,0.999916 ,0.999985 ,0.999994 ,0.999973 ,0.999928 ,0.99764 ,0.95845 ,0.994735 ,0.999649 ,0.998669 ,0.994697 ,0.99997 ,0.73903 ,0.999875 ,0.999875 ,0.981326 ,0.998918 ,0.999683 ,0.999922 ,0.998635 ,0.999781 ,0.999859 ,0.999841 ,0.999992 ,0.999984 ,0.999625 ,0.999859 ,0.999996 ,0.999978 ,0.999955 ,0.961011 ,0.993623 ,0.995991 ,0.997532 ,0.999387 ,0.999949 ,0.999903 ,0.999614 ,0.966036 ,0.999934 ,0.999999 ,0.999587 ,0.720167 ,0.999912 ,0.995588 ,0.937574 ,0.942364 ,0.799327 ,0.712899 ,0.997794 ,0.998321}
crnnTime(29.842200ms)
textLine(--boxThresh: value of boxThresh(float), default: 0.3)
textScores{0.994062 ,0.991381 ,0.999928 ,0.993981 ,0.99884 ,0.999979 ,0.999977 ,0.999741 ,0.999964 ,0.999987 ,0.999409 ,0.998612 ,0.957454 ,0.995777 ,0.999888 ,0.99215 ,0.999724 ,0.999984 ,0.930672 ,0.999918 ,0.999301 ,0.996731 ,0.999909 ,0.999744 ,0.998946 ,0.999988 ,0.962624 ,0.999664 ,0.999997 ,0.999997 ,0.999263 ,0.995889 ,0.999663 ,0.99448 ,0.993878 ,0.999925 ,0.999775 ,0.99861 ,0.999236 ,0.955161 ,0.999771 ,0.999997 ,0.999956 ,0.992426 ,0.999787 ,0.992837 ,0.99999 ,0.998532 ,0.832363 ,0.834685 ,0.997439 ,0.999437}
crnnTime(22.920900ms)
textLine(u --unClipRatio: value of unClipRatio(float), default: 2.0)
textScores{0.908146 ,0.858898 ,0.99408 ,0.992761 ,0.999694 ,0.999668 ,0.997444 ,0.975734 ,0.999825 ,0.995543 ,0.999991 ,0.999975 ,0.999974 ,0.998733 ,0.999495 ,0.998819 ,0.975385 ,0.990328 ,0.997796 ,0.997393 ,0.999921 ,0.999909 ,0.997237 ,0.999824 ,0.999982 ,0.700355 ,0.999939 ,0.999505 ,0.998322 ,0.966846 ,0.999864 ,0.999785 ,0.999991 ,0.999993 ,0.999989 ,0.999936 ,0.999678 ,0.999633 ,0.998713 ,0.80237 ,0.999491 ,0.999229 ,0.999807 ,0.999806 ,0.998152 ,0.536288 ,0.999924 ,1 ,0.998567 ,0.999084 ,0.999598 ,0.978772 ,0.999958 ,0.747404 ,0.928781 ,0.999204 ,0.96184 ,0.959914}
crnnTime(25.074600ms)
textLine(--doAngle: Enable(1)/Disable(O) Angle Net, default: Enable)
textScores{0.995228 ,0.9964 ,0.999402 ,0.999617 ,0.749414 ,0.999878 ,0.999882 ,0.99743 ,0.999993 ,0.998888 ,0.995596 ,0.999491 ,0.999664 ,0.999949 ,0.999953 ,0.989167 ,0.999999 ,0.999852 ,0.979189 ,0.998244 ,0.999726 ,0.999999 ,0.999998 ,0.999989 ,0.999986 ,0.999966 ,0.99768 ,0.999994 ,0.976733 ,0.940235 ,0.997309 ,0.999416 ,0.999952 ,0.86746 ,0.998723 ,0.91232 ,0.999995 ,0.997772 ,0.793995 ,0.999999 ,0.999992 ,0.995201 ,0.996947 ,0.999906 ,0.999999 ,0.999616 ,0.994014 ,0.999848 ,0.99635 ,0.987378 ,0.984729 ,0.706088 ,0.999911 ,0.999892 ,0.999889 ,0.999941 ,0.990215 ,0.999996}
crnnTime(24.038700ms)
textLine(A--mostAngle: Enable(1)/Disable(0) Most Possible Anglelndex, default: Enable)
textScores{0.999983 ,0.994983 ,0.973823 ,0.995088 ,0.995422 ,0.999969 ,0.999857 ,0.999896 ,0.999967 ,0.704219 ,0.998468 ,0.999997 ,0.999867 ,0.958974 ,0.999869 ,0.99958 ,0.996293 ,0.99999 ,0.997985 ,0.999998 ,0.993277 ,0.996858 ,0.998387 ,0.996998 ,0.999933 ,0.99999 ,0.999361 ,0.999294 ,0.999982 ,0.998339 ,0.999999 ,0.998184 ,0.51429 ,0.999516 ,0.989031 ,0.999919 ,0.999331 ,0.999998 ,0.999996 ,0.8374 ,0.978996 ,0.999866 ,0.999956 ,0.999964 ,0.999997 ,0.999988 ,0.997296 ,0.999987 ,0.973175 ,0.999997 ,0.999974 ,0.54188 ,0.999332 ,0.999995 ,0.863257 ,0.999997 ,0.999896 ,0.999998 ,0.999953 ,0.690234 ,0.901478 ,0.998933 ,0.999992 ,0.999781 ,0.849867 ,0.999783 ,0.925027 ,0.999495 ,0.927642 ,0.683695 ,0.999977 ,0.997139 ,0.974976 ,0.999992 ,0.99373 ,0.999117}
crnnTime(35.052300ms)
=====End detect=====
FullDetectTime(582.894200ms)
Reguired Parameters
-d --models: models directory
1--det: modelfile name of det
-2--cls: model file name ofcls.
3 --rec: model file name of rec
-4 --keys: keys file name
-i --image: path of target image
Optional Parameters
t--numThread: value of numThread(int), default: 4
-P --Padding: value of padding(int, defsult: 50
-s --maxSideLen: Long side of picture for resize(int), default: 1024
-b --boxScoreThresh: value of boxScoreThresh(float), default: 0.6
--boxThresh: value of boxThresh(float), default: 0.3
u --unClipRatio: value of unClipRatio(float), default: 2.0
--doAngle: Enable(1)/Disable(O) Angle Net, default: Enable
A--mostAngle: Enable(1)/Disable(0) Most Possible Anglelndex, default: Enable


#include <file.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

Local $searchString = "FullDetectTime"
Local $inputFile = "3333.png-result.txt"
Local $outputFile = "output.txt"

Local $hInputFile = FileOpen($inputFile, 0)
If $hInputFile = -1 Then
      MsgBox(0, "Error", "文件打开错误")
      Exit
EndIf

Local $hOutputFile = FileOpen($outputFile, 2 + 8)
Local $isFound = False
While True
      Local $line = FileReadLine($hInputFile)
      If @error = -1 Then
                ExitLoop
      EndIf

      If $isFound Then
                FileWriteLine($hOutputFile, $line)
      EndIf
      If StringInStr($line, $searchString) Then
                $isFound = True
      EndIf
WEnd
FileClose($hInputFile)
FileClose($hOutputFile)
If Not $isFound Then
      MsgBox(0, "错误", "没有查找到指定字符串")
Else
      MsgBox(0, "", FileRead($outputFile))
EndIf
Exit查找字符串所在行下面的内容不是固定的。
上面代码能实现。
用正则应该更快一些,
FullDetectTime.*?\r([\s\S]*?)\n\s*\r
但是不知道正则这样用对不对!


afan 发表于 2023-9-13 16:17:52

FullDetectTime\V+\R([\s\S]+)

风过无痕 发表于 2023-9-13 17:16:00

afan 发表于 2023-9-13 16:17


使用a版的正则,如果最后面有空白行的话,也会匹配到空白行。
FullDetectTime\V+\R([\s\S]+)\n\s*\r
我在后面加上红色的就把空白行去掉了,不知道这样处理对不对?

另外A版常用\V,请教A版,\V \R是什么意思呢?一般怎么用呢?一般的教程这两个都是小写的

afan 发表于 2023-9-13 17:34:49

风过无痕 发表于 2023-9-13 17:16
使用a版的正则,如果最后面有空白行的话,也会匹配到空白行。
FullDetectTime\V+\R([\s\S]+)\n\s*\r
我 ...

如果要排除最末可能有的空行可以FullDetectTime\V+\R([\s\S]+?)\s*$
正则里面大小写都是有不同意义的,\V是指非垂直空格,即非回车换行的所有字符;\R是指回车换行,但如果是单独的回车或换行也能匹配。这些帮助文档里都有说明。正则的写法可以千变万化,没有固定的模式或组合,达到目的就行。当然,数据量较大时不同的写法效率可能天壤之别。

风过无痕 发表于 2023-9-13 19:21:18

afan 发表于 2023-9-13 17:34
如果要排除最末可能有的空行可以
正则里面大小写都是有不同意义的,\V是指非垂直空格,即非回车换行的所 ...

谢谢a版的解惑,a版的正则功力真是深厚!
页: [1]
查看完整版本: 【已解决】查找指定字符串,获取指定字符串所在行后面的内容