Skip to content

Commit

Permalink
Uploading files
Browse files Browse the repository at this point in the history
  • Loading branch information
PayalKumari10 committed Jun 21, 2024
0 parents commit dc1b9cc
Show file tree
Hide file tree
Showing 18 changed files with 5,716 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["next/babel", "next/core-web-vitals"]
}
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz


# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.js`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
Binary file added app/favicon.ico
Binary file not shown.
40 changes: 40 additions & 0 deletions app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}

@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
}
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
}

@layer utilities {
.text-balance {
text-wrap: balance;
}
.gradient {
@apply bg-gradient-to-b from-white via-pink-300 to-gray-600;
}

.gradient-title {
@apply gradient text-transparent bg-clip-text;
}
}
21 changes: 21 additions & 0 deletions app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Inter } from "next/font/google";
import "./globals.css";

const inter = Inter({ subsets: ["latin"] });

export const metadata = {
title: "Thief Detector",
description: "Generated by creating object detection",
};

export default function RootLayout({ children }) {
return (
<html lang="en">
<body className={inter.className}>{children}
<footer style={{ textAlign: "center", padding: "10px", backgroundColor: "#f4f4f4", color: "black" }}>
CopyRight &copy; {new Date().getFullYear()} Payal Kumari, All Rights Reserved.
</footer>
</body>
</html>
);
}
14 changes: 14 additions & 0 deletions app/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import ObjectDetection from "@/components/object-detection";
// import Image from "next/image";

export default function Home() {
return (
<main className="flex min-h-screen flex-col items-center p-8">
<h1
className="gradient-title font-extrabold text-3xl md:text-6xl lg:text:8xl -tracking-tighter md:px-6 text-center"
>Thief Detection Alarm
</h1>
<ObjectDetection/>
</main>
);
}
91 changes: 91 additions & 0 deletions components/object-detection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"use client";

import React , {useEffect, useRef, useState} from "react";
import Webcam from "react-webcam";
import {load as cocoSSDLoad} from "@tensorflow-models/coco-ssd";
import * as tf from "@tensorflow/tfjs"
import { renderPredictions } from "@/utils/render.predictions";

let detectInterval;

const ObjectDetection = () => {
const [isLoading, setIsLoading] = useState(true);

const webcamRef = useRef(null);
const canvasRef = useRef(null);

async function runCoco() {
setIsLoading(true); // Set loading state to true when model loading starts
const net = await cocoSSDLoad();
setIsLoading(false); // Set loading state to false when model loading completes

detectInterval = setInterval(() => {
runObjectDetection(net); // will build this next
}, 10);
}

async function runObjectDetection(net) {
if (
canvasRef.current &&
webcamRef.current !== null &&
webcamRef.current.video?.readyState === 4
) {
canvasRef.current.width = webcamRef.current.video.videoWidth;
canvasRef.current.height = webcamRef.current.video.videoHeight;

// find detected objects
const detectedObjects = await net.detect(
webcamRef.current.video,
undefined,
0.6
);

// console.log(detectedObjects);

const context = canvasRef.current.getContext("2d");
renderPredictions(detectedObjects, context);
}
}

const showmyVideo = () => {
if (
webcamRef.current !== null &&
webcamRef.current.video?.readyState === 4
) {
const myVideoWidth = webcamRef.current.video.videoWidth;
const myVideoHeight = webcamRef.current.video.videoHeight;

webcamRef.current.video.width = myVideoWidth;
webcamRef.current.video.height = myVideoHeight;
}
};

useEffect(() => {
runCoco();
showmyVideo();
}, []);

return (
<div className="mt-8">
{isLoading ? (
<div className="gradient-text">Loading AI Model...</div>
) : (
<div className="relative flex justify-center items-center gradient p-1.5 rounded-md">
{/* webcam */}
<Webcam
ref={webcamRef}
className="rounded-md w-full lg:h-[720px]"
muted
/>
{/* canvas */}
<canvas
ref={canvasRef}
className="absolute top-0 left-0 z-99999 w-full lg:h-[720px]"
/>
</div>
)}
</div>
);
};

export default ObjectDetection;
7 changes: 7 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"paths": {
"@/*": ["./*"]
}
}
}
4 changes: 4 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};

export default nextConfig;
Loading

0 comments on commit dc1b9cc

Please sign in to comment.