{"action":"created","issue":{"url":"https://api.github.com/repos/Itseez/opencv/issues/5847","labels_url":"https://api.github.com/repos/Itseez/opencv/issues/5847/labels{/name}","comments_url":"https://api.github.com/repos/Itseez/opencv/issues/5847/comments","events_url":"https://api.github.com/repos/Itseez/opencv/issues/5847/events","html_url":"https://github.com/Itseez/opencv/issues/5847","id":123271700,"number":5847,"title":"potential bug  in VideoCapture_DShow","user":{"login":"yang3kui","id":6123579,"avatar_url":"https://avatars.githubusercontent.com/u/6123579?v=3","gravatar_id":"","url":"https://api.github.com/users/yang3kui","html_url":"https://github.com/yang3kui","followers_url":"https://api.github.com/users/yang3kui/followers","following_url":"https://api.github.com/users/yang3kui/following{/other_user}","gists_url":"https://api.github.com/users/yang3kui/gists{/gist_id}","starred_url":"https://api.github.com/users/yang3kui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yang3kui/subscriptions","organizations_url":"https://api.github.com/users/yang3kui/orgs","repos_url":"https://api.github.com/users/yang3kui/repos","events_url":"https://api.github.com/users/yang3kui/events{/privacy}","received_events_url":"https://api.github.com/users/yang3kui/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-21T12:34:17Z","updated_at":"2015-12-21T15:10:14Z","closed_at":null,"body":"I work on window 10 and want to capture image from a usb camera  using opencv 3.0. \r\n\r\nMy camera can only work at  YUY2_640_480_30FPS or MJPEG_640_480_90FPS. \r\n\r\nI prefer MJPEG_640_480_90FPS since it has higher frame rate, however, in defaut, my camera works at YUY2_640_480_30FPS.  In order to make it working at MJPEG_640_480_90FPS,  I thought I should write some codes like,\r\n\r\n\tcv::VideoCapture cap;\r\n\tcap.open(0);\r\n\tbool flag = cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));\r\n\tcap.set(CV_CAP_PROP_FPS, 90);\r\n\tcap.set(CV_CAP_PROP_FRAME_HEIGHT, 400);\r\n\tcap.set(CV_CAP_PROP_FRAME_WIDTH, 640);\r\n\r\nI tried, but it didn't work. My camera insisted on working at  YUY2_640_480_30FPS.\r\n\r\nI debuged and found that the failure is due to some strange codes in the following function\r\n\r\n      VideoCapture_DShow::setProperty(int propIdx, double propVal)\r\n\r\nThere you can found \r\n\r\n        if (m_width > 0 && m_height > 0)\r\n        {\r\n\t     if (m_width != g_VI.getWidth(m_index) || m_height != g_VI.getHeight(m_index) )\r\n            {\r\n                int fps = static_cast<int>(g_VI.getFPS(m_index));\r\n                g_VI.stopDevice(m_index);\r\n                g_VI.setIdealFramerate(m_index, fps);\r\n                g_VI.setupDeviceFourcc(m_index, m_width, m_height, m_fourcc);\r\n            }\r\n\r\n            bool success = g_VI.isDeviceSetup(m_index);\r\n            if (success)\r\n            {\r\n                m_widthSet = m_width;\r\n                m_heightSet = m_height;\r\n                m_width = m_height = m_fourcc = -1;\r\n            }\r\n            return success;\r\n        }\r\n\r\nThe device will only be reseted if m_width != g_VI.getWidth(m_index) || m_height != g_VI.getHeight(m_index).\r\n\r\nHowever, in my case, my camera only has two working modes, in both of which height = 640 and width = 400. So, logically, there is no way to change the working mode of my camera from YUY2_640_480_30FPS to MJPEG_640_480_90FPS.\r\n\r\nI modified\r\n\r\n         if (m_width != g_VI.getWidth(m_index) || m_height != g_VI.getHeight(m_index) )\r\n\r\nto \r\n\r\n         if (m_width != g_VI.getWidth(m_index) || m_height != g_VI.getHeight(m_index) || m_fourcc != g_VI.getFourcc(m_index)) .\r\n\r\n\r\nNow, it works. \r\n\r\nSo, is\r\n\r\n       if (m_width != g_VI.getWidth(m_index) || m_height != g_VI.getHeight(m_index) || m_fourcc != g_VI.getFourcc(m_index))\r\n\r\nbetter? \r\n\r\n If i have misunderstood something, can someone suggest a way to make my camera working at MJPEG_640_480_90FPS without modifying OPENCV's codes. \r\n\r\n\r\n           "},"comment":{"url":"https://api.github.com/repos/Itseez/opencv/issues/comments/166326352","html_url":"https://github.com/Itseez/opencv/issues/5847#issuecomment-166326352","issue_url":"https://api.github.com/repos/Itseez/opencv/issues/5847","id":166326352,"user":{"login":"alalek","id":4981219,"avatar_url":"https://avatars.githubusercontent.com/u/4981219?v=3","gravatar_id":"","url":"https://api.github.com/users/alalek","html_url":"https://github.com/alalek","followers_url":"https://api.github.com/users/alalek/followers","following_url":"https://api.github.com/users/alalek/following{/other_user}","gists_url":"https://api.github.com/users/alalek/gists{/gist_id}","starred_url":"https://api.github.com/users/alalek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alalek/subscriptions","organizations_url":"https://api.github.com/users/alalek/orgs","repos_url":"https://api.github.com/users/alalek/repos","events_url":"https://api.github.com/users/alalek/events{/privacy}","received_events_url":"https://api.github.com/users/alalek/received_events","type":"User","site_admin":false},"created_at":"2015-12-21T15:10:14Z","updated_at":"2015-12-21T15:10:14Z","body":"Does this call sequence work for you (set fps and fourcc after frame size)?\r\n```\r\ncap.set(CV_CAP_PROP_FRAME_HEIGHT, 400);\r\ncap.set(CV_CAP_PROP_FRAME_WIDTH, 640);\r\ncap.set(CV_CAP_PROP_FPS, 90);\r\nbool flag = cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));\r\n```\r\n\r\nBTW, Original code was added in this form a long time ago, so there is no chance to know why this check was commented out:\r\n```\r\nif( width != VI.getWidth(index) || height != VI.getHeight(index) ) //|| fourcc != VI.getFourcc(index) )\r\n```\r\nhttps://github.com/Itseez/opencv/commit/f0b8b81caa11b2b2a8d9d427705acda6d12673df#diff-2cb41154cefa4e53295b1fab5cc68e57R3327\r\n"}}