pipenv command summarising.

referenced from :

$ pip install pipenv
 brew install pipenv

make virtualenv
$ mkdir myenv
$ cd myenv
$ pipenv --python 3.6

install requirements pipenv
$ cd my_project
$ pipenv install

pipenv package install & uninstall
$ pipenv install beautifulsoup4
 pipenv uninstall beautifulsoup4

freeze → pip freeze > "requirements.txt"
$ pipenv lock

install package to development version
$ pipenv install --dev pytest

install development version requirements 
$ pipenv install --dev

activate pipenv virtualenv
$ pipenv shell

deactivate pipenv virtualenv
$ exit

run pipenv without activate
$ pipenv run which python
$ pipenv run python my_project.py

Python interpreter setting in Visual studio code 


Table(grid) detector

Table(grid) detector source code.
The code find table row & col lines in document image.


Table(Grid) Detector
buy : https://www.cvlecture.marearts.com/product-page/table-grid-detector
test : http://www.marearts.com/webapp/dtable/
github : https://github.com/MareArts/DTable

Usage source code
#include "DTable.h"

//for local computer
void main()

    CDTable cDT;

    //test image
    char str[255];
    for (int i = 0; i < 10; ++i)
        //make file string
        sprintf_s(str, "%d.jpg", i + 1);
        printf("%s open \n", str);

        Mat oimg = imread(str);

        if (oimg.empty())

        //get rect vector
        vector< GridV> vRect;
        if (cDT.FindGrid(oimg, vRect, 0, 0) == false)
            printf("Couldn't Find \n");

        //show table
        namedWindow("oimg", 0);
        int idx = 0;
        for (auto it : vRect)

            printf("%d grid :  (x:%d, y:%d, width:%d, height:%d \n", idx, it.rect.x, it.rect.y, it.rect.width, it.rect.height);

            if (it.pure)
                cv::rectangle(oimg, it.rect, CV_RGB(0, 255, 0), 2);
                cv::rectangle(oimg, it.rect, CV_RGB(255, 0, 0), 2);



        imshow("oimg", oimg);
        if (waitKey(0) == 'q')



Elastic image effect, python opencv example source code.

Elastic effect source code.
It can be useful when you want to augment image dataset.
and it is also good to make image effect.

Please refer code:

import numpy as np
import cv2
from scipy.ndimage.interpolation import map_coordinates
from scipy.ndimage.filters import gaussian_filter

def elastic(image, alpha, sigma, random_state=None):
"""Elastic deformation of images as described in [Simard2003]_.
.. [Simard2003] Simard, Steinkraus and Platt, "Best Practices for
Convolutional Neural Networks applied to Visual Document Analysis", in
Proc. of the International Conference on Document Analysis and
Recognition, 2003.
if random_state is None:
random_state = np.random.RandomState(None)

shape = image.shape
dx = gaussian_filter((random_state.rand(*shape) * 2 - 1), sigma, mode="constant", cval=0) * alpha
dy = gaussian_filter((random_state.rand(*shape) * 2 - 1), sigma, mode="constant", cval=0) * alpha
dz = np.zeros_like(dx)

x, y, z = np.meshgrid(np.arange(shape[1]), np.arange(shape[0]), np.arange(shape[2]))

indices = np.reshape(y+dy, (-1, 1)), np.reshape(x+dx, (-1, 1)), np.reshape(z, (-1, 1))
distored_image = map_coordinates(image, indices, order=1, mode='nearest') #wrap,reflect, nearest

return distored_image.reshape(image.shape)

#file read
o_img = cv2.imread('izone_oy.png')
elMat = elastic(o_img, alpha=5000, sigma=8, random_state=None)

cv2.imshow('origin', o_img)
cv2.imshow('elastic', elMat)


GitHub url :

python OpenCV, draw grid example source code

make well divided linear coordinate
And make pair coordinate

Please see code for detail explanation.

import numpy as np
import cv2
import sys

rows = 500
cols = 500
newMat_3ch = np.zeros((rows, cols, 3), dtype = "uint8") #3channel

step = 20
x = np.linspace(start=0, stop=rows, num=step)
y = np.linspace(start=0, stop=cols, num=step)

v_xy = []
h_xy = []
for i in range(step):
v_xy.append( [int(x[i]), 0, int(x[i]), rows-1] )
h_xy.append( [0, int(y[i]), cols-1, int(y[i])] )

for i in range(step):
[x1, y1, x2, y2] = v_xy[i]
[x1_, y1_, x2_, y2_] = h_xy[i]

cv2.line(newMat_3ch, (x1,y1), (x2, y2), (0,0,255),1 )
cv2.line(newMat_3ch, (x1_,y1_), (x2_, y2_), (255,0,0),1 )
cv2.imshow('newMat_3ch', newMat_3ch)


data dump by pickle in python

Data dump by pickle

see below example:

data dump to file 
import pickle
f = open("any_file.dmp', "wb")

data load by dump
data = pickle.loads(open("any_file.dmp", "rb").read())


_mask.so : undefined symbol: _Py_ZeroStruct

>git clone https://github.com/cocodataset/cocoapi.git
>cd cocoapi/PythonAPI
>sudo make
*** python 2.7
>python setup.py build_ext install
***python 3.x
>python3 setup.py build_ext install
>cp -r pycocotools <path_to_tensorflow>/models/research/


How to mount extra hdd permanently

> sudo -I blkid
/dev/sdb1: UUID="0687f976-6efe-4ac5-88dd-8fd863f8b8bf" TYPE="ext4" PARTUUID="1569f982-01"/dev/sda1: LABEL="cloudimg-rootfs" UUID="8ae3d910-2d2a-492d-8667-d0fa24e4d357" TYPE="ext4" PARTUUID="05ae307a-01"/dev/sdc1: UUID="e8abbf34-2cb2-471f-bac6-2a5caec81ad8" TYPE="ext4" PARTUUID="4c4db30a-01"

check uuid that you want to mount
>sudo nano /etc/fstab
Add this string end of file, but uuid must be your value, and ext4 also should be same with blkid information

UUID=e8abbf34-2cb2-471f-bac6-2a5caec81ad8 /media/datadisk ext4 defults,nofail    0       2

Thank you.