OpenCV: Save frame matrix to text file (Python)
<p>I have got a USB connected webcam and want to save captured frame to text file. Frame is numpy array and i need to get only red color values. So, here's my code: </p>

<pre><code>vc = cv2.VideoCapture(1)

if vc.isOpened():
    rval, frame = vc.read()
    frame = imutils.resize(frame, width=640, height=480)
    print(frame[...,...,2])
    savetxt('../test.txt', frame[...,...,2])
</code></pre>

<p><strong>print</strong> gets me this:</p>

<p>[[127 125 125 ..., 114 118 101]</p>

<p>[123 126 125 ..., 111 112 100]</p>

<p>[129 124 122 ..., 116 116 100]</p>

<p>..., </p>

<p>[121 120 121 ...,  97 104  88]</p>

<p>[118 121 121 ...,  96 103  90]</p>

<p>[116 122 120 ...,  97 105  90]]</p>

<p>But even if I could print the whole array, it does not fit terminal window.
So i'd like to save it to file but <strong>savetxt</strong> func is not working as I want. Here's the beginning of test.txt: 
1.270000000000000000e+02 1.250000000000000000e+02 1.250000000000000000e+02 </p>

<p>and so on.</p>

<p>I'm using OpenCv 3.1 and Python 2.7.12 </p>

<p>Any help? </p>

<p><code>savetxt</code> default format is <code>'%.18e'</code> which explains the format you're getting.</p>

<pre><code>numpy.savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='', footer='', comments='# ')[source]Â¶
</code></pre>

<p>Change the format specifier with <code>fmt</code> parameter to print integers instead of floats:</p>

<pre><code>savetxt('../test.txt', frame[...,...,2],fmt="%d")
</code></pre>

python osx opencv numpy