I need to transform an angled photographed pice of paper to a "flat" image. I found this question & solution here on Mathematics and tried it out for the image given in the solution:

The values of the image are (in the nomenclature of the other question): mx = 500 (width of image), my = 375 (height of image) and the points P1(164|346), P2(466|235), P3(363|0), P4(14|183) (for the point of origin at the left bottom) which lead over to the following system of linear equations:
$$ {\begin{bmatrix} 164&346&1&0&0&0&0&0\\ 466&235&1&0&0&0&0&0\\ 363&0&1&0&0&0&-181500&0\\ 14&183&1&0&0&0&-7000&-91500\\ 0&0&0&164&346&1&0&0\\ 0&0&0&466&235&1&-174750&-88125\\ 0&0&0&363&0&1&0&0\\ 0&0&0&14&183&1&-5250&-68625 \end{bmatrix}}^{-1} \cdot \begin{bmatrix} 0\\ 0\\500\\500\\0\\375\\0\\375 \end{bmatrix} = \begin{bmatrix} -0.3362 \\ -0.9147 \\ 371.6101 \\ -0.6139 \\ -0.3531 \\ 222.8487 \\ -0.0014 \\ -0.0032 \end{bmatrix} $$
But when I feed this result to the ImageMagick tool to actually perfom the transformation on the input image, a wrong image is returned.
convert -verbose ClyfV.jpg -alpha set -matte -virtual-pixel transparent -distort perspective-projection '-0.3362,-0.9147,371.6101,-0.6139,-0.3531,222.8487,-0.0014,-0.0032' 2.jpg
So my question is where I made a mistake in my calculation. One can imagine, that the coordinates are measured from the left top corner (more often used in computer graphics than the common mathematical coordinate origin), but that does not produce the right result - I've tried it already.
Finally I found the solution to my question: I might have made a mistake by using wrong coordinates in the calculation. I'm not exactly sure. I found other places explaining details behind the perspective transformation here, here and finally an example in C here.