Click here to Skip to main content
15,885,669 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have given a complex sequence shown below-

result = [[[[0.0, 7.0], [129.0, 7.0], [129.0, 48.0], [0.0, 48.0]],
  ('Firefox', 0.9971230626106262)],
 [[[170.0, 508.0], [668.0, 508.0], [668.0, 556.0], [170.0, 556.0]],
  ('CR No.: 211022200011481', 0.9427024126052856)],
 [[[1115.0, 512.0], [1322.0, 512.0], [1322.0, 552.0], [1115.0, 552.0]],
  ('OPD CARD', 0.9275292158126831)],
 [[[1964.0, 512.0], [2271.0, 512.0], [2271.0, 559.0], [1964.0, 559.0]],
  ('www.scbmch.in', 0.9585516452789307)],
 [[[170.0, 599.0], [583.0, 599.0], [583.0, 647.0], [170.0, 647.0]],
  ('Patient Name: Monika', 0.9691153764724731)],
 [[[1251.0, 596.0], [1576.0, 592.0], [1577.0, 643.0], [1252.0, 647.0]],
  ('Age/Sex: 28 Yr /F', 0.9872424006462097)],
 [[[174.0, 665.0], [543.0, 665.0], [543.0, 702.0], [174.0, 702.0]],
  ('D/O: Monika father', 0.89133220911026)],
 [[[1255.0, 658.0], [2034.0, 658.0], [2034.0, 705.0], [1255.0, 705.0]],
  ('Date & Time: 6-September-2022 17:28:17', 0.9425970315933228)],
 [[[166.0, 720.0], [801.0, 720.0], [801.0, 771.0], [166.0, 771.0]],
  ('Department: Cardiology(cardio 2)', 0.9899667501449585)],
 [[[1255.0, 724.0], [1857.0, 724.0], [1857.0, 771.0], [1255.0, 771.0]],
  ('Appointment Date: 16-Sep-2022', 0.9323211908340454)],
 [[[155.0, 790.0], [262.0, 790.0], [262.0, 830.0], [155.0, 830.0]],
  ('Vitals:', 0.9957624077796936)],
 [[[524.0, 793.0], [794.0, 793.0], [794.0, 830.0], [524.0, 830.0]],
  ('Chief Complaints:', 0.995205819606781)],
 [[[1983.0, 793.0], [2156.0, 793.0], [2156.0, 830.0], [1983.0, 830.0]],
  ('Diagnosis/', 0.979446530342102)],
 [[[1983.0, 841.0], [2248.0, 841.0], [2248.0, 881.0], [1983.0, 881.0]],
  ('Diagnosis(Prov):', 0.9228802919387817)],
 [[[159.0, 896.0], [229.0, 896.0], [229.0, 925.0], [159.0, 925.0]],
  ('Ht....', 0.9669005274772644)],
 [[[292.0, 892.0], [414.0, 892.0], [414.0, 928.0], [292.0, 928.0]],
  ('..(Cms)', 0.9294410943984985)],
 [[[1977.0, 924.0], [2183.0, 933.0], [2181.0, 984.0], [1974.0, 975.0]],
  ('Past History:', 0.9502112865447998)],
 [[[158.0, 953.0], [242.0, 963.0], [237.0, 999.0], [153.0, 989.0]],
  ('Wt....', 0.9631617069244385)],
 [[[284.0, 961.0], [369.0, 961.0], [369.0, 1002.0], [284.0, 1002.0]],
  ('..(Kg)', 0.9298592209815979)],
 [[[1983.0, 1009.0], [2079.0, 1009.0], [2079.0, 1049.0], [1983.0, 1049.0]],
  ('Hyper', 0.998813271522522)],
 [[[159.0, 1031.0], [240.0, 1031.0], [240.0, 1071.0], [159.0, 1071.0]],
  ('Pulse', 0.9149500131607056)],
 [[[328.0, 1026.0], [419.0, 1036.0], [414.0, 1076.0], [323.0, 1066.0]],
  ('../min', 0.9576079845428467)],
 [[[1976.0, 1041.0], [2219.0, 1050.0], [2218.0, 1101.0], [1975.0, 1092.0]],
  ('Tension: (Y/N)', 0.9596797823905945)],
 [[[162.0, 1108.0], [233.0, 1108.0], [233.0, 1137.0], [162.0, 1137.0]],
  ('BP:...', 0.8659010529518127)],
 [[[284.0, 1108.0], [421.0, 1108.0], [421.0, 1148.0], [284.0, 1148.0]],
  ('..mm/Hg', 0.8771561980247498)],
 [[[1983.0, 1126.0], [2230.0, 1126.0], [2230.0, 1166.0], [1983.0, 1166.0]],
  ('Diabetes: (Y/N)', 0.9567031860351562)],
 [[[159.0, 1177.0], [255.0, 1177.0], [255.0, 1217.0], [159.0, 1217.0]],
  ('Temp:', 0.9742925763130188)],
 [[[1986.0, 1199.0], [2189.0, 1199.0], [2189.0, 1239.0], [1986.0, 1239.0]],
  ('COPD: (Y/N)', 0.9035886526107788)],
 [[[162.0, 1254.0], [214.0, 1254.0], [214.0, 1283.0], [162.0, 1283.0]],
  ('RR:', 0.9956105351448059)],
 [[[303.0, 1254.0], [377.0, 1254.0], [377.0, 1283.0], [303.0, 1283.0]],
  ('/min', 0.9487172365188599)],
 [[[1983.0, 1272.0], [2245.0, 1272.0], [2245.0, 1312.0], [1983.0, 1312.0]],
  ('Oncology: (Y/N)', 0.9581263661384583)],
 [[[159.0, 1320.0], [266.0, 1320.0], [266.0, 1356.0], [159.0, 1356.0]],
  ('SPO2:..', 0.8974727988243103)],
 [[[1983.0, 1341.0], [2171.0, 1341.0], [2171.0, 1382.0], [1983.0, 1382.0]],
  ('CAD: (Y/N)', 0.9229832887649536)],
 [[[155.0, 1393.0], [384.0, 1393.0], [384.0, 1429.0], [155.0, 1429.0]],
  ('Investigations:', 0.9258691072463989)],
 [[[1976.0, 1403.0], [2275.0, 1407.0], [2274.0, 1459.0], [1975.0, 1455.0]],
  ('Tuberculosis: (Y/N)', 0.9428665041923523)],
 [[[521.0, 1436.0], [727.0, 1436.0], [727.0, 1473.0], [521.0, 1473.0]],
  ('Examination:', 0.993964433670044)],
 [[[1976.0, 1472.0], [2227.0, 1481.0], [2225.0, 1532.0], [1975.0, 1524.0]],
  ('Thyroid: (Y/N)', 0.9343023300170898)],
 [[[159.0, 1491.0], [362.0, 1491.0], [362.0, 1528.0], [159.0, 1528.0]],
  ('CBC/LFT/KFT', 0.9619587063789368)],
 [[[150.0, 1562.0], [252.0, 1552.0], [256.0, 1596.0], [154.0, 1606.0]],
  ('Blood', 0.9827973246574402)],
 [[[1983.0, 1561.0], [2219.0, 1561.0], [2219.0, 1601.0], [1983.0, 1601.0]],
  ('Surgery: (Y/N)', 0.9660006761550903)],
 [[[155.0, 1608.0], [377.0, 1608.0], [377.0, 1648.0], [155.0, 1648.0]],
  ('Sugar(R/F/PP)', 0.9385057091712952)]]



and I have to use python to filter the list for text-'Chief Complaints:' and get the coordinates for the text. As the text was detected using OCR, the indexing of the detected text's list won't be same always. So I have to use filter only on the text to get the coordinates. How to proceed?

What I have tried:

What I tried-
Python
myList = [('Chief Complaints:', 0.995205819606781)]

count = 0

for el in zip(myList,result):
    
    for t in el[1]:
        if t in el[0]:
            count += 1
    print(el)
    print(count)
Posted
Updated 8-Sep-22 21:31pm

1 solution

Try this:
Python
for items in result:
    element = items[1]
    if 'Chief Complaints' in element[0]: // first item of the tuple
        print(element)
        coordinates = items[0]
 
Share this answer
 
v2
Comments
M@153 9-Sep-22 5:41am    
@Richard MacCutchan Hi, thank you for the solution, But I want to get the coordinates of the text-'Chief Complaints'. Kindly suggest any solution.
Richard MacCutchan 9-Sep-22 6:01am    
Well you need to explain which items are the coordinates. Is it one or more of the first list, or the second item of the tuple?
M@153 9-Sep-22 6:44am    
The first list- [[524.0, 793.0], [794.0, 793.0], [794.0, 830.0], [524.0, 830.0]].
These are the coordinates I want to extract.
Richard MacCutchan 9-Sep-22 8:08am    
That is just the first item of each entry in the results list. See my updated solution.
M@153 12-Sep-22 0:04am    
It worked....Thank you for the solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900