Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add colonoscopy detection in a video #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
366 changes: 366 additions & 0 deletions .ipynb_checkpoints/6-WindowsPolypsDetection-checkpoint.ipynb

Large diffs are not rendered by default.

60 changes: 59 additions & 1 deletion 6-WindowsPolypsDetection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,64 @@
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import cv2\n",
"\n",
"font = cv2.FONT_HERSHEY_SIMPLEX \n",
"\n",
"cap= cv2.VideoCapture(r'C:\\Users\\HP\\Desktop\\polyps1.mp4')\n",
"\n",
"#For real time camera\n",
"#cap = cv2.VideoCapture(0)\n",
"\n",
"while(True):\n",
" # Capture frame-by-frame\n",
" ret, frame = cap.read()\n",
" width = int(cap.get(3)) \n",
" height = int(cap.get(4)) \n",
" max_pred = 0.0 # maximum prediction\n",
" max_box = [] # box for the polyp detection\n",
" # Our operations on the frame come here: find the box with max proba for being polyps\n",
" for win_size in window_sizes:\n",
" # Loop on both dimensions of the image\n",
" for top in range(0, height - win_size + 1, step):\n",
" for left in range(0, width - win_size + 1, step):\n",
" # compute the (top, left, bottom, right) of the bounding box\n",
" box = (top, left, top + win_size, left + win_size)\n",
"\n",
" # crop the original image\n",
" cropped_img = frame[box[0]:box[2], box[1]:box[3],:]\n",
"\n",
" # normalize the cropped image (the same processing used for the CNN dataset)\n",
" cropped_img = cropped_img * 1./255\n",
" # reshape from (150, 150, 3) to (1, 150, 150, 3) for prediction\n",
" cropped_img = cropped_img.reshape((1, cropped_img.shape[0], cropped_img.shape[1], cropped_img.shape[2]))\n",
"\n",
" # make a prediction for only one cropped small image \n",
" preds = model.predict(cropped_img, batch_size=None, verbose=0)\n",
" # print(box[0],box[2],box[1],box[3], preds[0][0])\n",
" if preds[0][0]> max_pred:\n",
" max_pred = preds[0][0]\n",
" max_box = box\n",
" \n",
" frame = cv2.rectangle(frame, (max_box[0],max_box[1]),(max_box[2],max_box[3]) , (255, 0, 0) , 2) \n",
" cv2.putText(frame,'Probability: '+str(max_pred) , (50, 50), font, 1, (0, 255, 255), 2, cv2.LINE_4)\n",
" # Display the resulting frame\n",
" cv2.imshow('frame',frame)\n",
" if cv2.waitKey(1) & 0xFF == ord('q'):\n",
" break\n",
"\n",
"# When everything done, release the capture\n",
"cap.release()\n",
"cv2.destroyAllWindows()"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -301,7 +359,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
Binary file added video_coloscopy.mp4
Binary file not shown.