i want to place on logo image on shirt image such that logo conform to curvature of shirt image using displacement map filter. But i am facing some issues kindly correct me where i am doing mistakes.
Here is my code snippet:
public void displacementMapFilter(final Mat map, final Mat target,int componentX, int componentY, int scaleX, int scaleY,Mat output)
{ if (componentX < 0 || componentX > 2 || componentY < 0 || componentY > 2) { System.out.println("!!! displacementMapFilter: componentX and componentY values must be in range [0,2]"); return; } if (target.size().width != map.size().width || target.size().height != map.size().height || target.type() != CvType.CV_8UC4) { System.out.println("!!! displacementMapFilter: map and target need to have the same dimensions, and target type must be CV_8UC4"); //return; } output.create(target.rows(), target.cols(), target.type()); // work with pixels // for (int x = 0; x < output.rows(); x++) for (int y = 0; y < output.cols(); y++) { /* Formula: * dstPixel[x, y] = srcPixel[x + ((componentX(x, y) - 128) * scaleX) / 256, * y + ((componentY(x, y) - 128) * scaleY) / 256)] */ int dx, dy;
int numChannels = map.channels();//is 3 for 8UC3 (e.g. RGB)
int frameSize = map.rows() * map.cols();
int numChannels2 = map.channels();//is 3 for 8UC3 (e.g. RGB)
int frameSize2 = output.rows() * map.cols();
byte[] mapByteBuffer = new byte[frameSize * numChannels];
byte[] byteBuffer = new byte[frameSize * numChannels];
byte[] outputByteBuffer = new byte[frameSize * numChannels];
dx = x + (getComponent(map.get(x, y), componentX) - 128) * scaleX / 256;
if (dx < 0) dx = 0;
if (dx >= output.rows()) dx = output.rows();
dy = y + (getComponent(map.get(x, y), componentY) - 128) * scaleY / 256;
if (dy < 0) dy = 0;
if (dy >= output.cols()) dy = output.cols();
//output.at<cv::Vec4b>(x, y) = target.at<cv::Vec4b>(dx, dy);
target.put(dx, dy, mapByteBuffer);
output.put(x, y, target.get(dx, dy));
}
}
}