-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The notebook of Preprocessor class #60
base: main
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## main #60 +/- ##
==========================================
- Coverage 97.09% 97.00% -0.09%
==========================================
Files 3 3
Lines 172 167 -5
==========================================
- Hits 167 162 -5
Misses 5 5
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@priyanshi-git can you try |
Yes this worked. Now the issue of displaying the result persists. The code shows the output as |
Nice!! Additionally, the notebook should be broken up into smaller cells - preprocessed = Preprocessor("/content/Images/Page.png") # scan the image and copy the scanned image
scanned = preprocessed.scan(inplace=True)
orig = scanned.copy()
# display scanned image here # remove noise
noise_free = preprocessed.remove_noise(
inplace=True, overriden_image=scanned
)
# display noiseless image here # thicken the ink to draw Hough lines better
thickened = preprocessed.thicken_font(
inplace=True, overriden_image=noise_free
)
# display thickened image here and so on... |
Hey !! I made the changes and everything seems fine except the last step and I don't understand why that's happening. Let me know what can be done |
The I will make a new release today, which should fix it in the |
@all-contributors please add @priyanshi-git for bug |
I've put up a pull request to add @priyanshi-git! 🎉 |
Merge conflict: @all-contributors please add @priyanshi-git for bug |
@priyanshi-git already contributed before to bug |
Hey @Saransh-cpp I guess its working perfectly now |
Looks good now! Could you convert this to a markdown file and upload it in this branch? Just copy-pasting the Jupyter notebook content, would be better for the reviews! |
Hey @Saransh-cpp, I created the notebook for examples of OCR, but the output of signboard doesn't look fine to me, some characters are wrong, the same was happening with the invoice example as well. |
Some characters will always be wrong, don't worry about them. I'll try to find a workaround for the failing check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this, @priyanshi-git! Apologies for the late review, and the large review :) The overall structure of the example looks good! I have addressed some changes below -
import cv2 | ||
from scipy import ndimage | ||
from ocred import Preprocessor | ||
from google.colab.patches import cv2_imshow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use cv2
or matplotlib
to show images in Jupyter
. (cv2.imshow
should work and this import can be removed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did use cv2.imshow
initially but it gave an error that this function is not functional anymore in colab, hence I had to import the new function separately and use it.
``` | ||
# rotate the original scanned image | ||
rotated = ndimage.rotate(orig, median_angle) | ||
|
||
cv2_imshow(rotated) | ||
``` | ||
|
||
![image](https://user-images.githubusercontent.com/82112540/184902055-61c50a47-7894-4d2d-aba7-89acfa4b53f1.png) | ||
|
||
``` | ||
# remove noise again | ||
final_img = preprocessed.remove_noise(inplace=True, overriden_image=rotated) | ||
|
||
cv2_imshow(final_img) | ||
``` | ||
|
||
![image](https://user-images.githubusercontent.com/82112540/184902140-42582eac-e765-44b6-b518-b8aa81ada09c.png) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove these, and add the inplace=True
example.
Notice how we don't need return values now, given that the functions are altering the pre_img
variable directly, without copying it, making the code efficient!
Would be nice to split this into cells too!
preprocessed = Preprocessor("path/to/image")
# scan the image and copy the scanned image
pre_img = preprocessed.scan(inplace=True)
# plot pre_img
# remove noise
preprocessed.remove_noise(
inplace=True, overriden_image=pre_img # the variable `pre_img` is altered 'inplace'
)
# plot pre_img
# thicken the ink to draw Hough lines better
preprocessed.thicken_font(
inplace=True, overriden_image=pre_img
)
# plot pre_img
# calculate the median angle of all the Hough lines
preprocessed.rotate(
inplace=True, overriden_image=pre_img
)
# plot pre_img
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should I use to plot the image ? Also, I think we need variable to save the changes and then plot the image because although we put inplace=True
when I tried to plot using cv2_imshow(pre-img)
the outputs didn't have any changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should I use to plot the image ? Also, I think we need variable to save the changes and then plot the image because although we put inplace=True when I tried to plot using cv2_imshow(pre-img) the outputs didn't have any changes.
This looks like a bug. Can you open a new issue for this? I will fix it this weekend probably. This is why sometimes I think it would have been better if I wrote ocred
in julia
.
from google.colab.patches import cv2_imshow | ||
|
||
|
||
preprocessed = Preprocessor("/content/images/CosmosOne.jpg") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the users will be using Jupyter
locally. You can make this change at the end, when you are done with running this code on colab!
preprocessed = Preprocessor("/content/images/CosmosOne.jpg") | |
preprocessed = Preprocessor("../images/CosmosOne.jpg") |
You can directly commit the suggestions here, and later propagate it to the notebook manually! |
Co-authored-by: Saransh <[email protected]>
Co-authored-by: Saransh <[email protected]>
Co-authored-by: Saransh <[email protected]>
Co-authored-by: Saransh <[email protected]>
Co-authored-by: Saransh <[email protected]>
Co-authored-by: Saransh <[email protected]>
@priyanshi-git, #71 fixes the bug! Turns out This should work now - # manually preprocessing an image
import cv2
from scipy import ndimage
from ocred import Preprocessor
preprocessed = Preprocessor("path/to/img.jpg")
# display preprocessor.img -> it should be the passed in image
# scan the image and copy the scanned image
preprocessed.scan()
# display preprocessed.img -> it should be scanned
orig = preprocessed.img.copy()
# remove noise
preprocessed.remove_noise()
# display preprocessed.img -> it should be noiseless
# thicken the ink to draw Hough lines better
preprocessed.thicken_font()
# display preprocessed.img -> it should be thickened
# calculate the median angle of all the Hough lines
_, median_angle = preprocessed.rotate()
# display preprocessed.img -> it should be rotated
# rotate the original scanned image
rotated = ndimage.rotate(orig, median_angle)
# display rotated -> the original scanned image should be rotated
# remove noise again
preprocessed = Preprocessor(rotated)
preprocessed.remove_noise()
# display prepreocessed.img-> the original scanned and rotated image should be noiseless
cv2.imwrite("preprocessed.png", preprocessed.img) |
So now, we can get rid of the two sections which were editing inplace and editing a copy. A single section with the example above should work! |
Added the new section of code
I am facing a different issue now i.e., although I installed ocred package the
Preprocessor
is not being imported it shows anImportError