First time here? Check out the FAQ!

Ask Your Question
-1

copyTo not working: Java

asked Mar 19 '17

Davaaron gravatar image

updated Mar 19 '17

Hi,

I'm retrieving a ROI of mat, want to manipulate its values and put the manipulated matrix back into the original matrix but it's not working, though.. I googled that result together as it seems to be the best documentation, but I'm stuck and don't know why the original matrix won't hold the new values. The code is as follows.

for (int i = 0; i < objectArray.length; i++) {

        Imgproc.rectangle(frame, objectArray[i].tl(), objectArray[i].br(), scalar, 3);
        Mat A = frame.submat(objectArray[i]);
        A.convertTo(A, CvType.CV_64FC3);
        int size = (int) (A.total() * A.channels());
        double[] temp = new double[size]; 
        A.get(0, 0, temp);
        for (int j = 0; j < size; j++)
            temp[j] = (temp[j] / 2);
        A.put(0, 0, temp);
        A.copyTo(frame.submat(objectArray[i]));
    }

where objectArray contains Rectangles, my ROIs and frame is my original Matrix, which is, of course, bigger than A. Can someone help me?

Edit: It's working on every webpage i see. In my case, nothing happens. The rectangular is drawn but thats it. Actually the RIO Image should appear darker, but it doesn't. When I try

A.copyTo(frame)

then the original image/mat has the same size as my ROI, what's definitely not wanted. I also tried applying a mask with the same size as my Matrix 'A', but the image was turned completely black afterwards. Seems like I'm running from one pitfall straight into the other. Would appreciate some help.

Preview: (hide)

Comments

Why downvoting wihtout comment? This isn't helping anyone ..

Davaaron gravatar imageDavaaron (Mar 20 '17)edit

1 answer

Sort by » oldest newest most voted
0

answered Mar 20 '17

berak gravatar image

updated Mar 20 '17

you simply cannot copy a 64FC3 image into a ROI of an 8UC3 image.

also, the whole conversion / copyTo is unnessecary, and you should avoid doing any operation on pixels.

it could be as easy as:

Mat A = frame.submat(rects[i]); // reference to "frame" pixels
Core.divide(2.0, A, A);         // in-place
Preview: (hide)

Comments

Hey, thanks for your answer. What about if I want to put some random pixels (or modify the pixels with an algorithm that's not within org.opencv.Core*)?

Davaaron gravatar imageDavaaron (Mar 20 '17)edit

Question Tools

1 follower

Stats

Asked: Mar 19 '17

Seen: 2,043 times

Last updated: Mar 20 '17