tatsy / lime

lime (Library for Image Editing)
http://tatsy.github.io/lime
MIT License
51 stars 16 forks source link

about examples/vector_field_imaging #3

Closed haVincy closed 7 years ago

haVincy commented 7 years ago

Hello, I have some question about using your LIC. I want to use LIC by optical flow.

The third parameter of calcOpticalFlowFarneback() is type CV_32FC2.

calcOpticalFlowFarneback(prevgray, img, flowUmat, 0.5, 1, 12, 2, 5, 1.1, 0); flowUmat.copyTo(flow);

I think I can use flow calculated by calcOpticalFlowFarneback. So I passed the flow to lic function but had something wrong.

printf("[LIC] Classic -> "); lime::npr::lic(classic, noise, flow, 20, lime::npr::LICType::Classic); printf("OK\n");

Should I do some pre-process on the flow image first? It seems like type error.

tatsy commented 7 years ago

Hello @AwenHuang

Thanks for your interest in my project. I did not completely understand your problem but what do you mean by "something wrong"?

You got some errors? the result was different from your expectation? or other problem?

haVincy commented 7 years ago

Thanks to your reply

I can already use your example code to create LIC image (circular). Imgur

My current problem is I want to use the flow image created by OpenCV function "calcOpticalFlowFarneback()". (the third parameter is type CV_32FC2 which is like vfield in LIC) cv::Mat vfield = cv::Mat(height, width, CV_32FC2);

Imgur

But I passed this flow image to LIC it has some errors. Imgur

Imgur

I think maybe the format of flow image (created by calcOpticalFlowFarneback()) it's not correct to your vfield?

tatsy commented 7 years ago

Hello @AwenHuang,

I am really sorry for the delay in responding.

Thank you for explaining your problem in detail. I understand your problem. I think the problem is that the output of OpenCV's optical flow method includes flows whose "length" or "L2-norm" are over 1.

As you can see in the example, the calcVectorField in https://github.com/tatsy/lime/blob/master/examples/vector_field_imaging/vector_field_imaging.cpp#L77 includes only the flows whose length are between 0 and 1.

Accordingly, I think normalizing your flows before computing LIC can solve your problem. If it's not working, please try other LIC algorithm than "Classic", i.e., Eulerian or Lunge-Kutta.

It is still not working, could you tell me the situation again, please? Thank you very much for your cooperation.

haVincy commented 7 years ago

@tatsy Thanks for your explanation and guid ! I will try when I have time as soon as possible and let you know the result. Sorry for late reply I'm busy this week (mid-term week haha).

haVincy commented 7 years ago

@tatsy Thanks a lot! It worked! But I didn't normalized optical flow vector field. I just change the LIC algorithm from classic to Eular method.

tatsy commented 7 years ago

Hello @AwenHuang,

Actually, normalizing the flow field is not mandatory. However, it can cause the problem particularly when you use the classical algorithm. Eulerian is relatively robust for the magnitude of flows, it can work for your situation.

Anyway, I am happy that your problem has been solved successfully. I will close this issue soon.