i want to ask that how can i run one file of python in another file in jupyter notebook

0 votes
motion_detection.ipynb

# Python program to implement

# Webcam Motion Detector

# importing OpenCV, time and Pandas library

import cv2, time, pandas

# importing datetime class from datetime library

from datetime import datetime

# Assigning our static_back to None

static_back = None

# List when any moving object appear

motion_list = [ None, None ]

# Time of movement

time = []

# Initializing DataFrame, one column is start

# time and other column is end time

df = pandas.DataFrame(columns = ["Start", "End"])

# Capturing video

video = cv2.VideoCapture(0)

# Infinite while loop to treat stack of image as video

while True:

# Reading frame(image) from video

check, frame = video.read()

# Initializing motion = 0(no motion)

motion = 0

# Converting color image to gray_scale image

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Converting gray scale image to GaussianBlur

# so that change can be find easily

gray = cv2.GaussianBlur(gray, (21, 21), 0)

# In first iteration we assign the value

# of static_back to our first frame

if static_back is None:

static_back = gray

continue

# Difference between static background

# and current frame(which is GaussianBlur)

diff_frame = cv2.absdiff(static_back, gray)

# If change in between static background and

# current frame is greater than 30 it will show white color(255)

thresh_frame = cv2.threshold(diff_frame, 30, 255, cv2.THRESH_BINARY)[1]

thresh_frame = cv2.dilate(thresh_frame, None, iterations = 2)

# Finding contour of moving object

cnts,_ = cv2.findContours(thresh_frame.copy(),

cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

for contour in cnts:

if cv2.contourArea(contour) < 10000:

continue

motion = 1

(x, y, w, h) = cv2.boundingRect(contour)

# making green rectangle arround the moving object

cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 3)

# Appending status of motion

motion_list.append(motion)

motion_list = motion_list[-2:]

# Appending Start time of motion

if motion_list[-1] == 1 and motion_list[-2] == 0:

time.append(datetime.now())

# Appending End time of motion

if motion_list[-1] == 0 and motion_list[-2] == 1:

time.append(datetime.now())

# Displaying image in gray_scale

cv2.imshow("Gray Frame", gray)

# Displaying the difference in currentframe to

# the staticframe(very first_frame)

cv2.imshow("Difference Frame", diff_frame)

# Displaying the black and white image in which if

# intensity difference greater than 30 it will appear white

cv2.imshow("Threshold Frame", thresh_frame)

# Displaying color frame with contour of motion of object

cv2.imshow("Color Frame", frame)

key = cv2.waitKey(1)

# if q entered whole process will stop

if key == ord('q'):

# if something is movingthen it append the end time of movement

if motion == 1:

time.append(datetime.now())

break

# Appending time of motion in DataFrame

for i in range(0, len(time), 2):

df = df.append({"Start":time[i], "End":time[i + 1]}, ignore_index = True)

# Creating a CSV file in which time of movements will be saved

df.to_csv("Time_of_movements.csv")

video.release()

# Destroying all the windows

cv2.destroyAllWindows()

SEND_SMS.ipynb

 client = clx.xms.Client(service_plan_id='06bc3faedc7847719c8168029baafe27', token='b8bcb227f46e44348e3640d2bb6400cb')

            create = clx.xms.api.MtBatchTextSmsCreate()
            create.sender = '447537404817'
            create.recipients = {'9231400155'}
            create.body = 'This is a test message from your Sinch account'

            try:
             batch = client.create_batch(create)
            except (requests.exceptions.RequestException,
              clx.xms.exceptions.ApiException) as ex:
              print('Failed to communicate with XMS: %s' % str(ex))
            

i want to run the second script once motion == 1 in first script what can I do?
Dec 15, 2020 in Python by Ramsha
• 120 points
56 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

I want to download a file from the website by web scraping. Can anyone explain how to do this in jupyter lab (python) with an example?

Hey, Web scraping is a technique to automatically ...READ MORE

answered Apr 7, 2020 in Python by Gitika
• 65,870 points
581 views
0 votes
1 answer

How to write content of one file to another file in Python?

The following code snippet might solve your ...READ MORE

answered Aug 26, 2019 in Python by Neel
• 3,020 points
150 views
0 votes
1 answer

How do I append one string to another in Python?

If you only have one reference to ...READ MORE

answered Oct 22, 2018 in Python by SDeb
• 13,250 points
140 views
0 votes
0 answers
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,858 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,432 views