{"action":"created","comment":{"url":"https://api.github.com/repos/Denpeer/ContextProject/pulls/comments/30951429","id":30951429,"diff_hunk":"@@ -0,0 +1,195 @@\n+package com.funkydonkies.camdetect;\n+\n+import java.awt.image.BufferedImage;\n+import java.util.Arrays;\n+\n+import org.opencv.core.Core;\n+import org.opencv.core.Mat;\n+import org.opencv.core.Point;\n+import org.opencv.core.Scalar;\n+import org.opencv.imgproc.Imgproc;\n+\n+import com.funkydonkies.w4v3.Bridge;\n+\n+/**\n+ * This class performs the image matrix math and is used by VideoCap to get the current image to display in the frame.\n+ * this includes setting the bg, thresholding into foreground/background, and identifying the interestPoints\n+ * which are used as controlPoints and can be accessed via the Bridge method getControlPoints() \n+ * and getXDIST() to know the x interval between elements of the array returned by getControlPoints().\n+ * also the found interestPoints are draws on the image as visual reference.\n+ * @author Olivier Dikken\n+ *\n+ */\n+public class Mat2Image implements Bridge {\n+    private Mat mat = new Mat();\n+    private BufferedImage img;\n+    private byte[] dat;\n+    private Mat bg = new Mat();\n+    private Mat res = new Mat();\n+    private Boolean bgSet = false;\n+    private float[] interestPoints;\n+    private static final int XDIST = 20;\n+    private static final int MEDBLUR = 5;\n+    private static final int MAXCOL = 255;\n+    private static final int THRESHBLOCKSIZE = 71;\n+    private static final int IGNORESIZE = 7;\n+    private static final int CIRCLEDIAM = 5;\n+    private static final int NUMCHANNELS = 3;\n+    \n+    private int numPoints = 0;\n+    \n+    /** \n+     * Empty Constructor.\n+     */\n+    public Mat2Image() {\n+\n+    }\n+    \n+    /**\n+     * Mat matrix to image; get space of mat matrix -> does image processing and finds interest points.\n+     * @param imMatrix matrix of image\n+     */\n+    public Mat2Image(final Mat imMatrix) {\n+        getSpace(imMatrix);\n+    }\n+    \n+    /**\n+     * Get the Mat image matrix.\n+     * @return mat image matrix\n+     */\n+    public Mat getMat() {\n+    \treturn mat;\n+    }\n+    \n+    /**\n+     * When 'b' is pressed the class MyFrame calls setBG on VideoCap which calls this method.\n+     * the current image matrix becomes the mat matrix identifying the background (used by threshIt method).\n+     */\n+    public void setBg() {\n+    \tbg = mat.clone();\n+    \tbgSet = true;\n+    \tSystem.out.println(\"Background has been set\");\n+    }\n+    \n+    /**\n+     * Note:\n+     * absdiff(img,bg)>img2GRAY>blur>thresh.\n+     * <p> Res is used instead of mat to keep mat as the 'input matrix'.</p>\n+     * @param imIn incomming frame\n+     * @param background background\n+     * @return result of img processing\n+     */\n+    public Mat threshIt(final Mat imIn, final Mat background) {\n+    \tCore.absdiff(imIn, background, res);\n+    \tImgproc.cvtColor(res, res, Imgproc.COLOR_BGR2GRAY); //convert to grayscale for processign\n+    \tImgproc.medianBlur(res, res, MEDBLUR);\n+    \tImgproc.adaptiveThreshold(res, res, MAXCOL, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY, THRESHBLOCKSIZE, IGNORESIZE);\n+    \treturn res;\n+    }\n+    \n+    /**\n+     * Currently this method finds the highest point for every x belonging to XDIST*k with k a natural.\n+     * @param im input matrix of image\n+     */\n+    public void updateIP(final Mat im) {\n+    \t//XDIST = 20; xrange = 640; total interest points = 640/20=32;\n+    \tfinal double tempdiv = im.size().width / XDIST;\n+    \tnumPoints = (int) Math.floor(tempdiv);\n+    \tinterestPoints = new float[numPoints];\n+    \tArrays.fill(interestPoints, (float) im.size().height);\n+    \t//for every chosen x find the highest pixel value equal to 0\n+    \tfor (int i = 0; i < numPoints; i++) {\n+    \t\tfor (int j = 0; j < im.size().height; j++) {\n+    \t\t\tfinal double val = im.get(j, i * XDIST)[0];\n+    \t\t\tif (val == 0.0) {\n+    \t\t\t\tinterestPoints[i] = j;\n+    \t\t\t\tbreak;\n+    \t\t\t}\n+    \t\t}\n+    \t}\n+    }\n+    \n+    /**\n+     * Draws red dots at the locations of the found interestPoints to be used as visual feedback.\n+     * @param matMatrix the image matrix\n+     * @param iP array of interestPoints\n+     * @return the processed image converted to BGR with red circles drawn at the interest point locations\n+     */\n+    public Mat drawInterestPoints(final Mat matMatrix, final float[] iP) {\n+    \tfinal Mat im = new Mat();\n+    \tImgproc.cvtColor(matMatrix, im, Imgproc.COLOR_GRAY2BGR); //convert back to bgr to draw interest points for visual feedback\n+    \tfor (int i = 0; i < iP.length; i++) {\n+    \t\tCore.circle(im, new Point(i * XDIST, iP[i]), CIRCLEDIAM, new Scalar(MAXCOL), 0, 0, 2);\n+    \t}\n+    \treturn im;\n+    }\n+    \n+    /**\n+     * Make sure the byte and bufferedimage are of right size and 'color' settings.\n+     * @param matMatrix matrix of the image\n+     */\n+    public void prepareSpace(final Mat matMatrix) {\n+    \tfinal int w = mat.cols(), h = mat.rows();\n+        if (dat == null || dat.length != w * h * NUMCHANNELS) {\n+            dat = new byte[w * h * NUMCHANNELS];\n+        }\n+        if (img == null || img.getWidth() != w || img.getHeight() != h\n+            || img.getType() != BufferedImage.TYPE_3BYTE_BGR) {\n+                img = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);\n+        }\n+    }\n+    \n+    /**\n+     * Sets the matrix properties.\n+     * calls the methods to threshold the matrix (foreground/background).\n+     * then calls the methods to update the interestPoints and draw them on the image as visual feedback.\n+     * @param matMatrix the image matrix\n+     */\n+    public void getSpace(final Mat matMatrix) {\n+    \t//convert from RGB to BGR\n+    \tImgproc.cvtColor(matMatrix, matMatrix, Imgproc.COLOR_RGB2BGR);\n+        if (bgSet) { //if bg is set then subtract foreground from background\n+        \tres = threshIt(mat, bg);\n+        \tupdateIP(res);\n+        \tres = drawInterestPoints(res, interestPoints); //convert to color image and draw red dots at the interest point locations\n+        \tprepareSpace(res);\n+        } else {\n+        \tthis.res = mat;\n+        \tprepareSpace(res);\n+        }\n+    }\n+    \n+    /**\n+     * This method is called by the VideoCap class.\n+     * it calls the image processing method and returns the processed segmented contoured image.\n+     * @param matMatrix matrix of image\n+     * @return processed image matrix as image\n+     */\n+        BufferedImage getImage(final Mat matMatrix) {\n+            getSpace(mat);\n+            res.get(0, 0, dat);\n+            img.getRaster().setDataElements(0, 0, \n+                               res.cols(), res.rows(), dat);\n+        return img;\n+    }\n+        \n+    /**\n+     * Method comes from implementing the bridge interface.\n+     * used by classes outside of camdetect package to access the control points.\n+     * @return float array containing the control points\n+     */\n+\tpublic float[] getControlPoints() {\n+\t\treturn Arrays.copyOf(interestPoints, numPoints);","path":"src/main/java/com/funkydonkies/camdetect/Mat2Image.java","position":182,"original_position":182,"commit_id":"f0099c7200bbd7eb34971563d87b3cbfae229115","original_commit_id":"f0099c7200bbd7eb34971563d87b3cbfae229115","user":{"login":"Danilodum14","id":5946575,"avatar_url":"https://avatars.githubusercontent.com/u/5946575?v=3","gravatar_id":"","url":"https://api.github.com/users/Danilodum14","html_url":"https://github.com/Danilodum14","followers_url":"https://api.github.com/users/Danilodum14/followers","following_url":"https://api.github.com/users/Danilodum14/following{/other_user}","gists_url":"https://api.github.com/users/Danilodum14/gists{/gist_id}","starred_url":"https://api.github.com/users/Danilodum14/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Danilodum14/subscriptions","organizations_url":"https://api.github.com/users/Danilodum14/orgs","repos_url":"https://api.github.com/users/Danilodum14/repos","events_url":"https://api.github.com/users/Danilodum14/events{/privacy}","received_events_url":"https://api.github.com/users/Danilodum14/received_events","type":"User","site_admin":false},"body":"fixed bug","created_at":"2015-05-24T09:51:47Z","updated_at":"2015-05-24T09:51:47Z","html_url":"https://github.com/Denpeer/ContextProject/pull/24#discussion_r30951429","pull_request_url":"https://api.github.com/repos/Denpeer/ContextProject/pulls/24","_links":{"self":{"href":"https://api.github.com/repos/Denpeer/ContextProject/pulls/comments/30951429"},"html":{"href":"https://github.com/Denpeer/ContextProject/pull/24#discussion_r30951429"},"pull_request":{"href":"https://api.github.com/repos/Denpeer/ContextProject/pulls/24"}}},"pull_request":{"url":"https://api.github.com/repos/Denpeer/ContextProject/pulls/24","id":36099790,"html_url":"https://github.com/Denpeer/ContextProject/pull/24","diff_url":"https://github.com/Denpeer/ContextProject/pull/24.diff","patch_url":"https://github.com/Denpeer/ContextProject/pull/24.patch","issue_url":"https://api.github.com/repos/Denpeer/ContextProject/issues/24","number":24,"state":"open","locked":false,"title":"Camera detection to add in SplineCurve","user":{"login":"Danilodum14","id":5946575,"avatar_url":"https://avatars.githubusercontent.com/u/5946575?v=3","gravatar_id":"","url":"https://api.github.com/users/Danilodum14","html_url":"https://github.com/Danilodum14","followers_url":"https://api.github.com/users/Danilodum14/followers","following_url":"https://api.github.com/users/Danilodum14/following{/other_user}","gists_url":"https://api.github.com/users/Danilodum14/gists{/gist_id}","starred_url":"https://api.github.com/users/Danilodum14/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Danilodum14/subscriptions","organizations_url":"https://api.github.com/users/Danilodum14/orgs","repos_url":"https://api.github.com/users/Danilodum14/repos","events_url":"https://api.github.com/users/Danilodum14/events{/privacy}","received_events_url":"https://api.github.com/users/Danilodum14/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-05-24T08:27:50Z","updated_at":"2015-05-24T09:51:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"94efddaab7d269115635bd251e6101dea2cbdfeb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Denpeer/ContextProject/pulls/24/commits","review_comments_url":"https://api.github.com/repos/Denpeer/ContextProject/pulls/24/comments","review_comment_url":"https://api.github.com/repos/Denpeer/ContextProject/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Denpeer/ContextProject/issues/24/comments","statuses_url":"https://api.github.com/repos/Denpeer/ContextProject/statuses/f0099c7200bbd7eb34971563d87b3cbfae229115","head":{"label":"Denpeer:cameradetection","ref":"cameradetection","sha":"f0099c7200bbd7eb34971563d87b3cbfae229115","user":{"login":"Denpeer","id":5969147,"avatar_url":"https://avatars.githubusercontent.com/u/5969147?v=3","gravatar_id":"","url":"https://api.github.com/users/Denpeer","html_url":"https://github.com/Denpeer","followers_url":"https://api.github.com/users/Denpeer/followers","following_url":"https://api.github.com/users/Denpeer/following{/other_user}","gists_url":"https://api.github.com/users/Denpeer/gists{/gist_id}","starred_url":"https://api.github.com/users/Denpeer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Denpeer/subscriptions","organizations_url":"https://api.github.com/users/Denpeer/orgs","repos_url":"https://api.github.com/users/Denpeer/repos","events_url":"https://api.github.com/users/Denpeer/events{/privacy}","received_events_url":"https://api.github.com/users/Denpeer/received_events","type":"User","site_admin":false},"repo":{"id":34375417,"name":"ContextProject","full_name":"Denpeer/ContextProject","owner":{"login":"Denpeer","id":5969147,"avatar_url":"https://avatars.githubusercontent.com/u/5969147?v=3","gravatar_id":"","url":"https://api.github.com/users/Denpeer","html_url":"https://github.com/Denpeer","followers_url":"https://api.github.com/users/Denpeer/followers","following_url":"https://api.github.com/users/Denpeer/following{/other_user}","gists_url":"https://api.github.com/users/Denpeer/gists{/gist_id}","starred_url":"https://api.github.com/users/Denpeer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Denpeer/subscriptions","organizations_url":"https://api.github.com/users/Denpeer/orgs","repos_url":"https://api.github.com/users/Denpeer/repos","events_url":"https://api.github.com/users/Denpeer/events{/privacy}","received_events_url":"https://api.github.com/users/Denpeer/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Denpeer/ContextProject","description":"Queue game","fork":false,"url":"https://api.github.com/repos/Denpeer/ContextProject","forks_url":"https://api.github.com/repos/Denpeer/ContextProject/forks","keys_url":"https://api.github.com/repos/Denpeer/ContextProject/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Denpeer/ContextProject/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Denpeer/ContextProject/teams","hooks_url":"https://api.github.com/repos/Denpeer/ContextProject/hooks","issue_events_url":"https://api.github.com/repos/Denpeer/ContextProject/issues/events{/number}","events_url":"https://api.github.com/repos/Denpeer/ContextProject/events","assignees_url":"https://api.github.com/repos/Denpeer/ContextProject/assignees{/user}","branches_url":"https://api.github.com/repos/Denpeer/ContextProject/branches{/branch}","tags_url":"https://api.github.com/repos/Denpeer/ContextProject/tags","blobs_url":"https://api.github.com/repos/Denpeer/ContextProject/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Denpeer/ContextProject/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Denpeer/ContextProject/git/refs{/sha}","trees_url":"https://api.github.com/repos/Denpeer/ContextProject/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Denpeer/ContextProject/statuses/{sha}","languages_url":"https://api.github.com/repos/Denpeer/ContextProject/languages","stargazers_url":"https://api.github.com/repos/Denpeer/ContextProject/stargazers","contributors_url":"https://api.github.com/repos/Denpeer/ContextProject/contributors","subscribers_url":"https://api.github.com/repos/Denpeer/ContextProject/subscribers","subscription_url":"https://api.github.com/repos/Denpeer/ContextProject/subscription","commits_url":"https://api.github.com/repos/Denpeer/ContextProject/commits{/sha}","git_commits_url":"https://api.github.com/repos/Denpeer/ContextProject/git/commits{/sha}","comments_url":"https://api.github.com/repos/Denpeer/ContextProject/comments{/number}","issue_comment_url":"https://api.github.com/repos/Denpeer/ContextProject/issues/comments{/number}","contents_url":"https://api.github.com/repos/Denpeer/ContextProject/contents/{+path}","compare_url":"https://api.github.com/repos/Denpeer/ContextProject/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Denpeer/ContextProject/merges","archive_url":"https://api.github.com/repos/Denpeer/ContextProject/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Denpeer/ContextProject/downloads","issues_url":"https://api.github.com/repos/Denpeer/ContextProject/issues{/number}","pulls_url":"https://api.github.com/repos/Denpeer/ContextProject/pulls{/number}","milestones_url":"https://api.github.com/repos/Denpeer/ContextProject/milestones{/number}","notifications_url":"https://api.github.com/repos/Denpeer/ContextProject/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Denpeer/ContextProject/labels{/name}","releases_url":"https://api.github.com/repos/Denpeer/ContextProject/releases{/id}","created_at":"2015-04-22T07:23:59Z","updated_at":"2015-05-08T16:29:08Z","pushed_at":"2015-05-24T09:48:10Z","git_url":"git://github.com/Denpeer/ContextProject.git","ssh_url":"git@github.com:Denpeer/ContextProject.git","clone_url":"https://github.com/Denpeer/ContextProject.git","svn_url":"https://github.com/Denpeer/ContextProject","homepage":null,"size":21258,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":9,"forks":0,"open_issues":9,"watchers":0,"default_branch":"master"}},"base":{"label":"Denpeer:CustomCurveMesh","ref":"CustomCurveMesh","sha":"e0ee2ac2465713164cec2207dae7b5bd5ffc7b91","user":{"login":"Denpeer","id":5969147,"avatar_url":"https://avatars.githubusercontent.com/u/5969147?v=3","gravatar_id":"","url":"https://api.github.com/users/Denpeer","html_url":"https://github.com/Denpeer","followers_url":"https://api.github.com/users/Denpeer/followers","following_url":"https://api.github.com/users/Denpeer/following{/other_user}","gists_url":"https://api.github.com/users/Denpeer/gists{/gist_id}","starred_url":"https://api.github.com/users/Denpeer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Denpeer/subscriptions","organizations_url":"https://api.github.com/users/Denpeer/orgs","repos_url":"https://api.github.com/users/Denpeer/repos","events_url":"https://api.github.com/users/Denpeer/events{/privacy}","received_events_url":"https://api.github.com/users/Denpeer/received_events","type":"User","site_admin":false},"repo":{"id":34375417,"name":"ContextProject","full_name":"Denpeer/ContextProject","owner":{"login":"Denpeer","id":5969147,"avatar_url":"https://avatars.githubusercontent.com/u/5969147?v=3","gravatar_id":"","url":"https://api.github.com/users/Denpeer","html_url":"https://github.com/Denpeer","followers_url":"https://api.github.com/users/Denpeer/followers","following_url":"https://api.github.com/users/Denpeer/following{/other_user}","gists_url":"https://api.github.com/users/Denpeer/gists{/gist_id}","starred_url":"https://api.github.com/users/Denpeer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Denpeer/subscriptions","organizations_url":"https://api.github.com/users/Denpeer/orgs","repos_url":"https://api.github.com/users/Denpeer/repos","events_url":"https://api.github.com/users/Denpeer/events{/privacy}","received_events_url":"https://api.github.com/users/Denpeer/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Denpeer/ContextProject","description":"Queue game","fork":false,"url":"https://api.github.com/repos/Denpeer/ContextProject","forks_url":"https://api.github.com/repos/Denpeer/ContextProject/forks","keys_url":"https://api.github.com/repos/Denpeer/ContextProject/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Denpeer/ContextProject/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Denpeer/ContextProject/teams","hooks_url":"https://api.github.com/repos/Denpeer/ContextProject/hooks","issue_events_url":"https://api.github.com/repos/Denpeer/ContextProject/issues/events{/number}","events_url":"https://api.github.com/repos/Denpeer/ContextProject/events","assignees_url":"https://api.github.com/repos/Denpeer/ContextProject/assignees{/user}","branches_url":"https://api.github.com/repos/Denpeer/ContextProject/branches{/branch}","tags_url":"https://api.github.com/repos/Denpeer/ContextProject/tags","blobs_url":"https://api.github.com/repos/Denpeer/ContextProject/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Denpeer/ContextProject/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Denpeer/ContextProject/git/refs{/sha}","trees_url":"https://api.github.com/repos/Denpeer/ContextProject/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Denpeer/ContextProject/statuses/{sha}","languages_url":"https://api.github.com/repos/Denpeer/ContextProject/languages","stargazers_url":"https://api.github.com/repos/Denpeer/ContextProject/stargazers","contributors_url":"https://api.github.com/repos/Denpeer/ContextProject/contributors","subscribers_url":"https://api.github.com/repos/Denpeer/ContextProject/subscribers","subscription_url":"https://api.github.com/repos/Denpeer/ContextProject/subscription","commits_url":"https://api.github.com/repos/Denpeer/ContextProject/commits{/sha}","git_commits_url":"https://api.github.com/repos/Denpeer/ContextProject/git/commits{/sha}","comments_url":"https://api.github.com/repos/Denpeer/ContextProject/comments{/number}","issue_comment_url":"https://api.github.com/repos/Denpeer/ContextProject/issues/comments{/number}","contents_url":"https://api.github.com/repos/Denpeer/ContextProject/contents/{+path}","compare_url":"https://api.github.com/repos/Denpeer/ContextProject/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Denpeer/ContextProject/merges","archive_url":"https://api.github.com/repos/Denpeer/ContextProject/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Denpeer/ContextProject/downloads","issues_url":"https://api.github.com/repos/Denpeer/ContextProject/issues{/number}","pulls_url":"https://api.github.com/repos/Denpeer/ContextProject/pulls{/number}","milestones_url":"https://api.github.com/repos/Denpeer/ContextProject/milestones{/number}","notifications_url":"https://api.github.com/repos/Denpeer/ContextProject/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Denpeer/ContextProject/labels{/name}","releases_url":"https://api.github.com/repos/Denpeer/ContextProject/releases{/id}","created_at":"2015-04-22T07:23:59Z","updated_at":"2015-05-08T16:29:08Z","pushed_at":"2015-05-24T09:48:10Z","git_url":"git://github.com/Denpeer/ContextProject.git","ssh_url":"git@github.com:Denpeer/ContextProject.git","clone_url":"https://github.com/Denpeer/ContextProject.git","svn_url":"https://github.com/Denpeer/ContextProject","homepage":null,"size":21258,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":9,"forks":0,"open_issues":9,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Denpeer/ContextProject/pulls/24"},"html":{"href":"https://github.com/Denpeer/ContextProject/pull/24"},"issue":{"href":"https://api.github.com/repos/Denpeer/ContextProject/issues/24"},"comments":{"href":"https://api.github.com/repos/Denpeer/ContextProject/issues/24/comments"},"review_comments":{"href":"https://api.github.com/repos/Denpeer/ContextProject/pulls/24/comments"},"review_comment":{"href":"https://api.github.com/repos/Denpeer/ContextProject/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Denpeer/ContextProject/pulls/24/commits"},"statuses":{"href":"https://api.github.com/repos/Denpeer/ContextProject/statuses/f0099c7200bbd7eb34971563d87b3cbfae229115"}}}}