MCPcopy Create free account
hub / github.com/creatale/node-dv / cartToPolar

Function cartToPolar

deps/opencv/modules/core/src/mathfuncs.cpp:442–501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

440
441
442void cartToPolar( InputArray src1, InputArray src2,
443 OutputArray dst1, OutputArray dst2, bool angleInDegrees )
444{
445 Mat X = src1.getMat(), Y = src2.getMat();
446 int type = X.type(), depth = X.depth(), cn = X.channels();
447 CV_Assert( X.size == Y.size && type == Y.type() && (depth == CV_32F || depth == CV_64F));
448 dst1.create( X.dims, X.size, type );
449 dst2.create( X.dims, X.size, type );
450 Mat Mag = dst1.getMat(), Angle = dst2.getMat();
451
452 const Mat* arrays[] = {&X, &Y, &Mag, &Angle, 0};
453 uchar* ptrs[4];
454 NAryMatIterator it(arrays, ptrs);
455 cv::AutoBuffer<float> _buf;
456 float* buf[2] = {0, 0};
457 int j, k, total = (int)(it.size*cn), blockSize = std::min(total, ((BLOCK_SIZE+cn-1)/cn)*cn);
458 size_t esz1 = X.elemSize1();
459
460 if( depth == CV_64F )
461 {
462 _buf.allocate(blockSize*2);
463 buf[0] = _buf;
464 buf[1] = buf[0] + blockSize;
465 }
466
467 for( size_t i = 0; i < it.nplanes; i++, ++it )
468 {
469 for( j = 0; j < total; j += blockSize )
470 {
471 int len = std::min(total - j, blockSize);
472 if( depth == CV_32F )
473 {
474 const float *x = (const float*)ptrs[0], *y = (const float*)ptrs[1];
475 float *mag = (float*)ptrs[2], *angle = (float*)ptrs[3];
476 Magnitude_32f( x, y, mag, len );
477 FastAtan2_32f( y, x, angle, len, angleInDegrees );
478 }
479 else
480 {
481 const double *x = (const double*)ptrs[0], *y = (const double*)ptrs[1];
482 double *angle = (double*)ptrs[3];
483
484 Magnitude_64f(x, y, (double*)ptrs[2], len);
485 for( k = 0; k < len; k++ )
486 {
487 buf[0][k] = (float)x[k];
488 buf[1][k] = (float)y[k];
489 }
490
491 FastAtan2_32f( buf[1], buf[0], buf[0], len, angleInDegrees );
492 for( k = 0; k < len; k++ )
493 angle[k] = buf[0][k];
494 }
495 ptrs[0] += len*esz1;
496 ptrs[1] += len*esz1;
497 ptrs[2] += len*esz1;
498 ptrs[3] += len*esz1;
499 }

Callers 1

cvCartToPolarFunction · 0.85

Calls 11

Magnitude_32fFunction · 0.85
FastAtan2_32fFunction · 0.85
Magnitude_64fFunction · 0.85
minFunction · 0.70
getMatMethod · 0.45
typeMethod · 0.45
depthMethod · 0.45
channelsMethod · 0.45
createMethod · 0.45
elemSize1Method · 0.45
allocateMethod · 0.45

Tested by

no test coverage detected