This project focuses on an image search problem: finding a specific face in an i
ID: 3870770 • Letter: T
Question
This project focuses on an image search problem: finding a specific face in an image or photo- graph. This is a problem that arises in many video surveillance applications (e.g., detecting a well-known terrorist's face in a crowd at an airline terminal) as well as in searching large collec- tions of digital images (e.g., finding all photos you took that contain your grandmother). In this assignment, we will focus on finding George P. Burdell, whose mugshots are shown in Figure 1, in an image that contains a crowd of faces, such as the sample scene in Figure 2. The faces in the scene, including George's, may be at varying distances from the camera, so they may appear scaled. For example in Figure 3a, George is scaled two times the original size and in Figure 3b he is scaled by a factor of three. All faces will be facing forward and upright (not rotated). Find George Variable ScaleExplanation / Answer
public static void image(){
try {
File f=new File("e:\asd\21.bmp");
//read the image into Buffer
BufferedImage imgb=ImageIO.read(f);
//get the image width + height
int imageW=imgb.getWidth();
int imageH=imgb.getHeight();
//define ONE dimsneion arry to read the image into
int imgArr[]=new int[imageW*imageH];
//read all the the pixels info into the array
imgb.getRGB(0,0,imageW,imageH,imgArr,0,imageW);
//NOTE: each element in the array will present: (all in Hex
values)
//1- Transperancy of the color
//2- Red color
//3- Green color
//4- Blue color
//
//example if the color in the image was Lime (between green
and yellow)
//its RGB is (186,255,0)
//the result will look like: FFBAFF00 , where:
//FF mean full opaque
//BA is 186
//FF is 255
//00 is 0
//this loop will show each pixel correspondent Hex value
String out="";
for (int i = 0; i < imgArr.length; i++) {
if (i % imageW ==0) out+=" ";
out+=Integer.toHexString(imgArr[i]).toUpperCase() + "
";
}
javax.swing.JOptionPane.showMessageDialog(null,out);
//the follwoing code fills the array in 2D array
//convert to 2D array
int img2D[][]=new int[imageW][imageH];
for (int x = 0; x < imageW; x++) {
for (int y = 0; y < imageH; y++) {
img2D[x][y]=imgArr[y*imageW+x];
}
}
//printing the new array (should be same as the previous
time)
out="";
for (int y = 0; y < imageH; y++) {
for (int x = 0; x < imageW; x++) {
out+=Integer.toHexString(img2D[x][y]) + " ";
}
out+=" ";
}
javax.swing.JOptionPane.showMessageDialog(null,out);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
String filename = File.separator+"tmp";
JFileChooser fileChooser = new JFileChooser(new File(filename));
fileChooser.showOpenDialog(mainPanel);
File file = fileChooser.getSelectedFile();
try {
BufferedImage imBuf = ImageIO.read(file);
int imgW = imBuf.getWidth();
int imgH = imBuf.getHeight();
int imgAr[] = new int[imgW*imgH];
//Bufferede img nin 0-0 dan w - h ye kadar olan ksmn rgb degerlerini alp
// imgAr dizisine döndürür;
imBuf.getRGB(0, 0, imgW, imgH, imgAr, 0, imgW);
//NOTE:
//Dizideki elemanlarn herbir Hex degerleri karslg
//1- Transparanlk //2- Red //3- Green //4- Blue
String out="Naber ibrahim ?";
out +=" "+Integer.toString(imgAr[381]);
JOptionPane.showMessageDialog(null, out);
//imgAr[] de tek boyutlu hali bulunuyor dizinin;
//ConvertTo 2D dimension
int img2D[][] = new int [imgH][imgW];
// row/col 447 382
//My image Height & Width
for(int i=0; i<imgH; i++)
for(int j=0; j<imgW; j++){
img2D[i][j] = imgAr[j+imgW*i];
}
out += " "+Integer.toString(img2D[0][381]);
JOptionPane.showMessageDialog(null, out);
} catch (IOException ex) {
Logger.getLogger(ImageProcessingView.class.getName()).log(Level.SEVERE, null, ex);
}
import java.awt.*;
02
import java.awt.event.*;
03
import java.awt.image.*;
04
import java.io.*;
05
import javax.imageio.*;
06
import javax.swing.*;
07
import java.util.Random;
08
09
10
11
public class BasicDisplay_2 extends Component{
12
13
private BufferedImage originalPic;
14
private Raster picRasterArray;
15
private DataBuffer picArray;
16
17
public void paint(Graphics g) {
18
g.drawImage(originalPic, 0, 0, null);
19
}
20
21
public BasicDisplay_2() {
22
try {
23
24
originalPic = ImageIO.read(new File("C://Users//Lily//Desktop//blue_balloons.jpg"));
25
26
27
picRasterArray = originalPic.getRaster();
28
29
30
System.out.println("************Image Properties***********");
31
System.out.println("Height in pixels: " + picRasterArray.getHeight());
32
System.out.println("Width in pixels: " + picRasterArray.getWidth());
33
System.out.println("Number of Color Bands: " + picRasterArray.getNumBands());
34
35
SampleModel st = picRasterArray.getSampleModel();
36
System.out.println("Image Sample Model: "+ st);
37
38
39
picArray = picRasterArray.getDataBuffer();
40
System.out.println("Total number of array elements in model: " +
41
picArray.getSize());
42
43
44
for(int i = 0; i<510; ++i){
45
st.setSample(i,300,0,0,picArray);
46
st.setSample(i,300,1,0,picArray);
47
st.setSample(i,300,2,0,picArray);
48
}
49
50
int []change = {255, 255, 255};
51
52
53
int randomRow, randomColumn;
54
55
Random randomGenerator = new Random(); //declartion of random generator object
56
57
for(int n=0; n<=80000; ++n){
58
randomColumn = randomGenerator.nextInt(510); //generate random column
59
randomRow = randomGenerator.nextInt(980); //generate random row
60
st.setPixel(randomColumn,randomRow,change,picArray); //change the pixel color
61
//at the row and column identified
62
}
63
} catch (IOException e) {
64
}
65
}
66
67
public Dimension getPreferredSize() {
68
if (originalPic == null) {
69
return new Dimension(800,700);
70
} else {
71
return new Dimension(originalPic.getWidth(null),
72
originalPic.getHeight(null));
73
}
74
}
75
76
public static void main(String[] args) {
77
78
JFrame f = new JFrame("Simple Image Processing");
79
80
f.addWindowListener(new WindowAdapter(){
81
public void windowClosing(WindowEvent e) {
82
System.exit(0);
83
}
84
});
85
86
f.add(new BasicDisplay_2());
87
f.pack();
88
f.setVisible(true);
89
}
90
}
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagepicker setDelegate:self];
[self presentViewController:imagepicker animated:YES completion:nil];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
//Pick from all folders in the gallery
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//Pick from PhotosAlbum(camera roll)
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
//Check PhotoLibrary available or not
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
//Check front Camera available or not
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront])
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[imagepicker dismissModalViewControllerAnimated:YES];
}
//Tells the delegate that the user cancelled the pick operation.
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
}
//Tells the delegate that the user picked an image. (Deprecated in iOS 3.0. Use imagePickerController:didFinishPickingMediaWithInfo: instead.)
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
}
- (void)showImagePicker
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Get the selected image.
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[picker dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
}
UIImagePickerController *picker;
picker = [[UIImagePickerController alloc] init];
[picker setDelegate:self];
[picker setSourceType:type];
[self presentViewController:picker animated:YES completion:nil];
To get the UIImage:
- (void)imagePickerController:(UIImagePickerController *)thePicker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Do something with "image"
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// users typically expect that if they took a photo it will be saved
if (thePicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.