extract only data with open cv?

asked 2016-06-13 05:02:28 -0600

yagami_md gravatar image

updated 2016-06-14 01:40:50 -0600

LBerger gravatar image

hey friends I tried to convert greyscale image to binary image , but now I want see only data without header ? how I can extract header only and data only ? after I want save header in file and data to in other file? nota:visual studio 2010 , opencv 2.4.9 , c programming

int _tmain(int argc, _TCHAR* argv[])
       {

//load image
IplImage* im_gray = cvLoadImage("image1.pgm",CV_LOAD_IMAGE_GRAYSCALE);
//convert to grey
//IplImage *im_rgb  = cvLoadImage("image.jpg");
//cvCvtColor(im_rgb,im_gray,CV_RGB2GRAY);
//convert to binary 
IplImage* im_bw = cvCreateImage(cvGetSize(im_gray),IPL_DEPTH_8U,1);
cvThreshold(im_gray, im_bw, 128, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);
//save to disk
cvSaveImage("image_final2.pgm",im_bw);
edit retag flag offensive close merge delete

Comments

2

As said in previous post C interface is deprecated. You can watch this video. If you are not agree with send message to the author.

Try to work with opencv 3.1 :

#include <opencv2/opencv.hpp> 
#include <iostream>
#include <fstream>

using namespace cv;

int main(int argc,char *argv[])
{
Mat m=imread("image1.pgm", CV_LOAD_IMAGE_GRAYSCALE);
Mat im_bw;
threshold(m,im_bw,thresh,255,THRESH_BINARY | THRESH_OTSU);
imshow("Threshold image",im_bw);
imwrite("thresh.png",im_bw);
}
LBerger gravatar imageLBerger ( 2016-06-14 01:54:29 -0600 )edit

full video link to save you the trouble of registering

boaz001 gravatar imageboaz001 ( 2016-06-14 04:22:33 -0600 )edit

I work with c nt c++ so MAT is for version c++ oki I have another question ,how I can access to pixel in image binary?

yagami_md gravatar imageyagami_md ( 2016-06-14 05:21:06 -0600 )edit

in opencv 3.1 method is at

LBerger gravatar imageLBerger ( 2016-06-14 06:25:19 -0600 )edit