Today I will show you load a image and save that image in many color changers.
- Make a new java project and import the Open CV libraries
- If you don't know about it please follow the first post with javaCV
IplImage image =cvLoadImage("img.JPG");
Make IplImage type variable it name is "image". "img.JPG" is assigned to to image.
IplImage hsv=cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,3);
- make a HSV type image
- cvcreateImage() need 3 parameters.
- size of image
- Type of image
- Nomber of frames in the image.
- if it is 1 ,it is gray color image
- if it is 3,it is colored image. 3 frames mean it have BGR(Blue,green,Red) frames.
- if it is 4,it contain four frames. That mean it have BGR frames and alpha frame. Alpha is transparancy of image
IplImage gray=cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
make a gray colored image
cvCvtColor(image,hsv,CV_BGR2HSV);
Convert original image to a HSV image
cvCvtColor(image, gray, CV_BGR2GRAY);
convert original image to gray image
cvShowImage("Original",image);
Make a window to show original image. Window name is "original"
cvShowImage("HSV", hsv);
Make a window to show HSV image. Window name is "HSV"
cvShowImage("Gray", gray);
Make a window to show Gray image. Window name is "Gray".
cvWaitKey();
cvSaveImage("HSV.JPG",hsv);
Save the hsv image in jpg type. It name will be "HSV.JPG"
cvSaveImage("Gray.JPG",gray);
Save the gray image in jpg type. It name will be "Gray.PGP"
cvReleaseImage(image);
cvReleaseImage(hsv);
cvReleaseImage(gray);
Release the memory allocated for image,hsv,gray variable we made.
Type above codes. Then go to project folde and paste a image to src folde.
Then go to your project folde. You can see that saved images.