Nekshay commited on
Commit
8ad5847
·
verified ·
1 Parent(s): 4f41a0d

Update mobileapp.txt

Browse files
Files changed (1) hide show
  1. mobileapp.txt +18 -56
mobileapp.txt CHANGED
@@ -1,62 +1,24 @@
1
- import React, { useState, useEffect } from 'react';
2
- import { View, Image, TouchableOpacity, Text } from 'react-native';
3
- import * as ImagePicker from 'expo-image-picker';
4
- import { ImageEditor } from 'react-native';
5
 
6
- const CropImage = () => {
7
- const [croppedImage, setCroppedImage] = useState(null); // State to store the cropped image URI
8
 
9
- useEffect(() => {
10
- getPermission();
11
- }, []);
12
 
13
- const getPermission = async () => {
14
- const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
15
- if (status !== 'granted') {
16
- alert('Permission denied!');
17
- }
18
- };
19
 
20
- const handleSelectImage = async () => {
21
- let result = await ImagePicker.launchImageLibraryAsync({
22
- mediaTypes: ImagePicker.MediaTypeOptions.Images,
23
- });
24
 
25
- if (!result.cancelled) {
26
- cropImage(result.uri);
27
- }
28
- };
29
 
30
- const cropImage = (imageUri) => {
31
- const cropData = {
32
- offset: { x: 100, y: 100 }, // x, y coordinates to start cropping
33
- size: { width: 200, height: 200 }, // width, height of the cropped area
34
- displaySize: { width: 200, height: 200 }, // desired width, height of the cropped image
35
- resizeMode: 'contain', // resizing mode
36
- };
37
-
38
- ImageEditor.cropImage(
39
- imageUri,
40
- cropData,
41
- (croppedURI) => {
42
- // Handle the cropped image URI
43
- console.log('Cropped image URI:', croppedURI);
44
- setCroppedImage({ uri: croppedURI });
45
- },
46
- (error) => {
47
- console.error('Error cropping image:', error);
48
- }
49
- );
50
- };
51
-
52
- return (
53
- <View>
54
- <TouchableOpacity onPress={handleSelectImage}>
55
- <Text>Select Image</Text>
56
- </TouchableOpacity>
57
- {croppedImage && <Image source={croppedImage} style={{ width: 200, height: 200 }} />}
58
- </View>
59
- );
60
- };
61
-
62
- export default CropImage;
 
1
+ import cv2
2
+ import numpy as np
 
 
3
 
4
+ # Load the image (assuming it's a binary image with edges)
5
+ image = cv2.imread('path/to/edge_detected_image.jpg', cv2.IMREAD_GRAYSCALE)
6
 
7
+ # Apply morphological operations to clean up the edges
8
+ kernel = np.ones((5, 5), np.uint8)
9
+ closed_image = cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel)
10
 
11
+ # Find contours in the closed image
12
+ contours, _ = cv2.findContours(closed_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
 
 
 
 
13
 
14
+ # Create a mask for the exterior contours
15
+ mask = np.zeros_like(image)
16
+ cv2.drawContours(mask, contours, -1, (255), thickness=cv2.FILLED)
 
17
 
18
+ # Apply the mask to the original image to get only the exterior edges
19
+ exterior_edges = cv2.bitwise_and(image, mask)
 
 
20
 
21
+ # Display the result or save it to a file
22
+ cv2.imshow('Exterior Edges', exterior_edges)
23
+ cv2.waitKey(0)
24
+ cv2.destroyAllWindows()