Comments (4)
This could be a simple weird cropping issue @sakshamarora1.
from handwrite.
Hey @yashlamba I encountered the same thing, but I found that if I converted my scanned image to a gray-scale image and then only used pixels that were below a certain darkness threshold it improved the quality.
Original on the left and cleaned version on the right:
Font improvement:
The code I wrote is here, happy to help make a PR if you like.
scanned_jpg = os.path.join(self.sheets_path, "with_lines.jpg")
cleaned_image = cv2.imread(scanned_jpg)
original_image_in_gray = cv2.cvtColor(cleaned_image, cv2.COLOR_BGR2GRAY)
threshold_level = 150
# To get specific coordinates of the pixels, use the following line:
# coords = np.column_stack(np.where(gray < threshold_level))
# Create mask of all pixels lower than threshold level
mask = original_image_in_gray < threshold_level
# Color the pixels in the mask
cleaned_image[mask] = (0, 0, 0)
# Remove all pixels not in the mask
cleaned_image[~mask] = (255, 255, 255)
# Convert jpg_img to cv2.COLOR_BGR2GRAY
updated_image = cv2.cvtColor(cleaned_image, cv2.COLOR_BGR2GRAY)
both_images = np.concatenate((original_image_in_gray, updated_image), axis=1)
cv2.imshow('Side by Side', both_images)
cv2.waitKey()
from handwrite.
Hi @chriscohoat, The new output looks much better (We also use something very similar but a different approach) but the threshold value you used is something we are trying to figure out.
If you look here: https://github.com/cod-ed/handwrite/blob/440f59153fe02fc96503fd87f9c64b105c8ceb71/handwrite/sheettopng.py#L79-L92
We default to a threshold of 200, if I am not wrong and it is configurable, @sakshamarora1 will have more context on this. We also have #3 open for a long time to fix this. In short, the problem we have is that the threshold that worked for your input might not work for others, maybe figuring it out dynamically based on the input would be interesting.
More related to #68.
from handwrite.
Hi @chriscohoat . The new output looks a lot better! As @yashlamba said we need to figure out how to dynamically set the best threshold value in order to get better results just like you did.
Also, the default threshold_value is configurable here in the config json file:
https://github.com/cod-ed/handwrite/blob/440f59153fe02fc96503fd87f9c64b105c8ceb71/handwrite/default.json#L1-L2
This was initially done so that everyone can set it accordingly as each input is different. I've opened an issue to track this since I missed it before - #70
from handwrite.
Related Issues (20)
- handwrite: cli: Add optional params to modify font metadata
- docs: Add info about handwrite-web
- actions: python-publish: explicitly checkout main branch
- IndexError: list index out of range HOT 1
- BUG: Unable to create font using jpg HOT 1
- BUG: Grey highlights in the form get added to the font
- Docs: Document new changes that include tweakable parameters in the cli and config file
- docs: mkdocs feature not working on contributing section HOT 1
- docs: contributing: Add docs on how to build docs locally HOT 2
- sheettopng: Use contour approximation for improving contour cropping code segment
- pngtosvg: Merge thresholding part in pngToBmp to sheettopng.py code to accommodate variable lighting in inputs
- Add requirements.txt
- Cannot convert the sample handwritten_font.jpg file to font.ttf file HOT 1
- OpenCV error while using the handwrite.exe on windows 10 HOT 1
- FileNotFoundError: [WinError 2] The system cannot find the file specified
- FileNotFoundError: [Errno 2] No such file or directory: 'fontforge'
- Multi language handwrite? HOT 1
- Zero clue whatsoever :) HOT 7
- Error no. 2: Unable to find file HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from handwrite.