Ask Your Question
-1

copyTo not working: Java

asked 2017-03-19 13:58:42 -0500

Davaaron gravatar image

updated 2017-03-19 15:51:12 -0500

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.

edit retag flag offensive close merge delete

Comments

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

Davaaron gravatar imageDavaaron ( 2017-03-19 18:09:14 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-03-20 01:23:27 -0500

berak gravatar image

updated 2017-03-20 01:37:01 -0500

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
edit flag offensive delete link more

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 ( 2017-03-20 06:40:53 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-03-19 13:58:42 -0500

Seen: 221 times

Last updated: Mar 20