{"action":"created","issue":{"url":"https://api.github.com/repos/opencv/opencv/issues/11068","repository_url":"https://api.github.com/repos/opencv/opencv","labels_url":"https://api.github.com/repos/opencv/opencv/issues/11068/labels{/name}","comments_url":"https://api.github.com/repos/opencv/opencv/issues/11068/comments","events_url":"https://api.github.com/repos/opencv/opencv/issues/11068/events","html_url":"https://github.com/opencv/opencv/issues/11068","id":304931387,"node_id":"MDU6SXNzdWUzMDQ5MzEzODc=","number":11068,"title":"Warp image with optical flow to produce a new image","user":{"login":"juliohm","id":3345261,"node_id":"MDQ6VXNlcjMzNDUyNjE=","avatar_url":"https://avatars1.githubusercontent.com/u/3345261?v=4","gravatar_id":"","url":"https://api.github.com/users/juliohm","html_url":"https://github.com/juliohm","followers_url":"https://api.github.com/users/juliohm/followers","following_url":"https://api.github.com/users/juliohm/following{/other_user}","gists_url":"https://api.github.com/users/juliohm/gists{/gist_id}","starred_url":"https://api.github.com/users/juliohm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliohm/subscriptions","organizations_url":"https://api.github.com/users/juliohm/orgs","repos_url":"https://api.github.com/users/juliohm/repos","events_url":"https://api.github.com/users/juliohm/events{/privacy}","received_events_url":"https://api.github.com/users/juliohm/received_events","type":"User","site_admin":false},"labels":[{"id":9731374,"node_id":"MDU6TGFiZWw5NzMxMzc0","url":"https://api.github.com/repos/opencv/opencv/labels/question%20(invalid)","name":"question (invalid)","color":"000000","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-03-13T20:53:12Z","updated_at":"2018-08-22T10:33:45Z","closed_at":"2018-03-17T19:30:13Z","author_association":"NONE","body":"I tried asking in the forum, but it seems pretty much inactive. I am not sure what I am doing wrong, but the code below doesn't generate the expected output. I have `im1` and `im2` (attached below) for which I compute the optical flow. Then I want to apply the flow to `im1` to double check that it produces `im2`:\r\n\r\n![0001](https://user-images.githubusercontent.com/3345261/37369136-79851124-26c5-11e8-9820-685d6a636caf.png)\r\n![0002](https://user-images.githubusercontent.com/3345261/37369145-7cdaf9c4-26c5-11e8-9d87-c2048be99267.png)\r\n\r\n```python\r\nimport cv2\r\nimport numpy as np\r\nfrom imageio import imread\r\n\r\nim1 = np.asarray(imread(\"0001.png\"))\r\nim2 = np.asarray(imread(\"0002.png\"))\r\nim1 = np.float64(im1 / 255)\r\nim2 = np.float64(im2 / 255)\r\n\r\nflow = cv2.calcOpticalFlowFarneback(im1, im2, None, 0.5, 3, 15, 3, 5, 1.2, 0)\r\n\r\ndef draw_hsv(flow):\r\n    h, w = flow.shape[:2]\r\n    fx, fy = flow[:,:,0], flow[:,:,1]\r\n    ang = np.arctan2(fy, fx) + np.pi\r\n    v = np.sqrt(fx*fx+fy*fy)\r\n    hsv = np.zeros((h, w, 3), np.uint8)\r\n    hsv[...,0] = ang*(180/np.pi/2)\r\n    hsv[...,1] = 255\r\n    hsv[...,2] = cv2.normalize(v, None, 0, 255, cv2.NORM_MINMAX)\r\n    bgr = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)\r\n    return bgr\r\n\r\ndef warp_flow(img, flow):\r\n    h, w = flow.shape[:2]\r\n    flow = -flow\r\n    flow[:,:,0] += np.arange(w)\r\n    flow[:,:,1] += np.arange(h)[:,np.newaxis]\r\n    res = cv2.remap(img, flow, None, cv2.INTER_LINEAR)\r\n    return res\r\n\r\nhsv = draw_hsv(flow)\r\nim2w = warp_flow(im1*255, flow)\r\ncv2.imwrite(\"/tmp/flow.jpg\",hsv)\r\ncv2.imwrite(\"/tmp/im1.jpg\", im1*255)\r\ncv2.imwrite(\"/tmp/im2.jpg\", im2*255)\r\ncv2.imwrite(\"/tmp/im2w.jpg\", im2w)\r\n```\r\n\r\nThe printed images do not look correct. Could you please provide some help on how to fix this use case?"},"comment":{"url":"https://api.github.com/repos/opencv/opencv/issues/comments/414988196","html_url":"https://github.com/opencv/opencv/issues/11068#issuecomment-414988196","issue_url":"https://api.github.com/repos/opencv/opencv/issues/11068","id":414988196,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNDk4ODE5Ng==","user":{"login":"juliohm","id":3345261,"node_id":"MDQ6VXNlcjMzNDUyNjE=","avatar_url":"https://avatars1.githubusercontent.com/u/3345261?v=4","gravatar_id":"","url":"https://api.github.com/users/juliohm","html_url":"https://github.com/juliohm","followers_url":"https://api.github.com/users/juliohm/followers","following_url":"https://api.github.com/users/juliohm/following{/other_user}","gists_url":"https://api.github.com/users/juliohm/gists{/gist_id}","starred_url":"https://api.github.com/users/juliohm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliohm/subscriptions","organizations_url":"https://api.github.com/users/juliohm/orgs","repos_url":"https://api.github.com/users/juliohm/repos","events_url":"https://api.github.com/users/juliohm/events{/privacy}","received_events_url":"https://api.github.com/users/juliohm/received_events","type":"User","site_admin":false},"created_at":"2018-08-22T10:33:45Z","updated_at":"2018-08-22T10:33:45Z","author_association":"NONE","body":"Yes, that is what I remember doing at that time, and it worked for me. I\ncan try find the code again when I have access to my laptop.\n\nOn Wed, Aug 22, 2018, 12:42 AM EQ <notifications@github.com> wrote:\n\n> hi @juliohm <https://github.com/juliohm> , you said that \"The code works\n> fine if we don't normalize the images and leave the values between\n> [0,255]\". Which means that change the \"im1 = np.float64(im1 / 255) and im2\n> = np.float64(im2 / 255)\" to \"im1 = np.float64(im1) im2 = np.float64(im2)\"\n> works fine for you? It seems doesn't work for me only change this settings.\n>\n> —\n> You are receiving this because you were mentioned.\n> Reply to this email directly, view it on GitHub\n> <https://github.com/opencv/opencv/issues/11068#issuecomment-414941947>,\n> or mute the thread\n> <https://github.com/notifications/unsubscribe-auth/ADMLbXr8kXoO1dgLgwSDL0Kn3Bmv72ETks5uTQtwgaJpZM4Spbwz>\n> .\n>\n"}}
{"actor":{"display_login":"juliohm"}}