Spaces:
Sleeping
Sleeping
HuggingFace-SK
commited on
Commit
·
6224ce2
1
Parent(s):
012ed80
show output
Browse files- app.py +9 -1
- static/index.js +6 -0
app.py
CHANGED
|
@@ -21,17 +21,25 @@ def analyse():
|
|
| 21 |
frame = request.json.get('key')
|
| 22 |
cv_frame = data_uri_to_image(frame)
|
| 23 |
gray_image = cv2.cvtColor(cv_frame, cv2.COLOR_BGR2GRAY)
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# Optional: Apply thresholding or other preprocessing techniques
|
| 26 |
# _, thresh_image = cv2.threshold(gray_image, 150, 255, cv2.THRESH_BINARY)
|
| 27 |
|
| 28 |
# Use pytesseract to extract text
|
| 29 |
-
results = reader.readtext(
|
| 30 |
results_array =[]
|
| 31 |
for (bbox, text, prob) in results:
|
| 32 |
results_array.append(f"Detected text: {text} (Confidence: {prob})")
|
| 33 |
|
| 34 |
# Iterate through the results and format them
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
return str(results_array)
|
| 36 |
|
| 37 |
|
|
|
|
| 21 |
frame = request.json.get('key')
|
| 22 |
cv_frame = data_uri_to_image(frame)
|
| 23 |
gray_image = cv2.cvtColor(cv_frame, cv2.COLOR_BGR2GRAY)
|
| 24 |
+
blur = cv2.bilateralFilter(gray_image,4,20,20)
|
| 25 |
+
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8)) # histograme of distributed pixel values
|
| 26 |
+
equalized = clahe.apply(blur)
|
| 27 |
|
| 28 |
# Optional: Apply thresholding or other preprocessing techniques
|
| 29 |
# _, thresh_image = cv2.threshold(gray_image, 150, 255, cv2.THRESH_BINARY)
|
| 30 |
|
| 31 |
# Use pytesseract to extract text
|
| 32 |
+
results = reader.readtext(equalized)
|
| 33 |
results_array =[]
|
| 34 |
for (bbox, text, prob) in results:
|
| 35 |
results_array.append(f"Detected text: {text} (Confidence: {prob})")
|
| 36 |
|
| 37 |
# Iterate through the results and format them
|
| 38 |
+
cv2.imshow("clahe", equalized)
|
| 39 |
+
cv2.imshow("blur", blur)
|
| 40 |
+
cv2.imshow("orig", gray_image)
|
| 41 |
+
cv2.waitKey(0)
|
| 42 |
+
|
| 43 |
return str(results_array)
|
| 44 |
|
| 45 |
|
static/index.js
CHANGED
|
@@ -89,6 +89,12 @@ function send_frame(dataUrl) {
|
|
| 89 |
.then(response => response.text())
|
| 90 |
.then(data => {
|
| 91 |
console.log(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
})
|
| 93 |
.catch((error) => {
|
| 94 |
console.error('Error:', error);
|
|
|
|
| 89 |
.then(response => response.text())
|
| 90 |
.then(data => {
|
| 91 |
console.log(data)
|
| 92 |
+
var span = document.createElement('span');
|
| 93 |
+
span.textContent = data;
|
| 94 |
+
span.style.color = 'black';
|
| 95 |
+
span.style.fontSize = '16px';
|
| 96 |
+
document.body.appendChild(span);
|
| 97 |
+
|
| 98 |
})
|
| 99 |
.catch((error) => {
|
| 100 |
console.error('Error:', error);
|