I researched because I wanted to convert the photo data into black and white binary and input it to Blender.
The following sample program is used as a reference.
python - Converting an OpenCV Image to Black and White - Stack Overflow
import cv as cv1
import cv2 as cv
import numpy as np
import sys
argvs = sys.argv
#Photo file
src = argvs[1]
#output data
output = argvs[2]
im_gray = cv.imread(src, cv.CV_LOAD_IMAGE_GRAYSCALE)
im_gray_mat = cv1.fromarray(im_gray)
im_bw = cv1.CreateImage(cv1.GetSize(im_gray_mat), cv1.IPL_DEPTH_8U, 1)
im_bw_mat = cv1.GetMat(im_bw)
threshold = 0
cv1.Threshold(im_gray_mat, im_bw_mat, threshold, 255, cv1.CV_THRESH_BINARY | cv1.CV_THRESH_OTSU)
cv.imshow('gray image', np.asarray(im_bw_mat))
cv.waitKey(0)
cv.destroyAllWindows()
import cv as cv1
import cv2 as cv
import numpy as np
import sys
argvs = sys.argv
src = argvs[1]
output = argvs[2]
im_gray = cv.imread(src, cv.CV_LOAD_IMAGE_GRAYSCALE)
im_gray_mat = cv1.fromarray(im_gray)
im_bw = cv1.CreateImage(cv1.GetSize(im_gray_mat), cv1.IPL_DEPTH_8U, 1)
im_bw_mat = cv1.GetMat(im_bw)
threshold = 0
cv1.Threshold(im_gray_mat, im_bw_mat, threshold, 255, cv1.CV_THRESH_BINARY | cv1.CV_THRESH_OTSU)
print np.asarray(im_bw_mat)
a = np.asarray(im_bw_mat)
np.savetxt(output, a, fmt='%10.5f', delimiter='\t')
I felt that I would need linear algebra.
Recommended Posts