This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
im=Image.open("1.jpg") | |
#im=im.rotate(1) | |
im.save("e.jpg") | |
im2=im.convert("L") | |
im2.save("b.jpg") | |
threshold = 100 | |
im = im2.point(lambda p: p > threshold and 255) | |
im.save("d.jpg") | |
img="d.jpg" | |
result = tesseract.ProcessPagesWrapper(img,api) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from collections import OrderedDict | |
def rename_state_dict_keys(source, key_transformation, target=None): | |
""" | |
source -> Path to the saved state dict. | |
key_transformation -> Function that accepts the old key names of the state | |
dict as the only argument and returns the new key name. | |
target (optional) -> Path at which the new state dict should be saved |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import math | |
import time | |
SLEEP_TIME = 0.1 | |
class MyMapDataset(torch.utils.data.Dataset): | |
def __init__(self, size): | |
self.dataset = [i for i in range(size)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This is a workaround for `examples/run_mlm.py` for pretraining models | |
with big text files line-by-line. | |
For the time being, `datasets` is facing some issues dealing with really | |
big text files, so we use a custom dataset until this is fixed. | |
August 3th 2021 | |
Author: Juan Manuel Pérez |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os.path | |
import collections | |
from operator import itemgetter | |
WORDFILE = '/usr/share/dict/words' | |
class Autocorrect(object): | |
""" | |
Very simplistic implementation of autocorrect using ngrams. | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from future import print_function | |
import os.path | |
import collections | |
from operator import itemgetter | |
if hasattr(__builtins__, 'raw_input'): | |
input = raw_input | |
WORDFILE = '/usr/share/dict/words' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cv::Point2f RotatePoint(const cv::Point2f& p, float rad) | |
{ | |
const float x = std::cos(rad) * p.x - std::sin(rad) * p.y; | |
const float y = std::sin(rad) * p.x + std::cos(rad) * p.y; | |
const cv::Point2f rot_p(x, y); | |
return rot_p; | |
} | |
cv::Point2f RotatePoint(const cv::Point2f& cen_pt, const cv::Point2f& p, float rad) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int maximalRectangle(vector<vector<char> > &matrix) { | |
if(matrix.size()==0 || matrix[0].size()==0)return 0; | |
vector<vector<int>>m(matrix.size()+1,vector<int>(matrix[0].size()+1,0)); | |
for(int i=0;i<matrix.size();i++) | |
for(int j=matrix[0].size()-1;j>=0;j--) | |
m[i][j]=matrix[i][j]=='1'?1+m[i][j+1]:0; | |
int max=0; | |
for(int i=0;i<matrix[0].size();i++){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <std::vector> | |
#include <opencv2/core/core.hpp> | |
#include <iostream> | |
#include <stdio.h> | |
/* | |
This work by Ryan Muller released under the Creative Commons CC0 License | |
http://creativecommons.org/publicdomain/zero/1.0/ | |
*/ | |
/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <std::vector> | |
#include <opencv2/core/core.hpp> | |
#include <iostream> | |
#include <stdio.h> | |
/* | |
This work by Ryan Muller released under the Creative Commons CC0 License | |
http://creativecommons.org/publicdomain/zero/1.0/ | |
*/ | |
/** |